0
내가 배치이 방법이 속성을 무시하는 것 같다 '는'문자열의 끝이 Novel.class
에서 문자열의 시작 부분에있는 경우 : 내가 NovelController
이 인덱스 방법이정렬 기준 : 사용자 정의
def sort_name
display_name = self.name
if display_name.match(/^the/i)
arr = display_name.split(/^the/i)
display_name = "#{arr[1]}, The"
end
display_name
:
def index
@novels = Novel.all
@novels.to_a.sort! { |a,b| a.sort_name.downcase <=> b.sort_name.downcase }
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @novels }
end
end
보기에서 나는 단지 sort_name
을 표시합니다. sort_name
이 표시되지만 소설은 여전히 name
으로 정렬됩니다. 아무도 결함을 볼 수 있습니까? 감사.
어떤 이유로 든 수정 된 문자열이 기본값 앞에 실제로 배치됩니다. 예를 들어, "옐로우 하느님, The"은 "Allan"앞에 있고 ... "그 생각은 어떤가? –
@JoeEssey : 음, 아마도 activerecord 일괄 처리가 잘못되었습니다. 'Novel.all.to_a.sort ...' –
그건 실제로 내가 가지고있는 것입니다 :'@novels = Novel.all.to_a.sort {| a, b | a.sort_name.downcase <=> b.sort_name.downcase}' –