I am kind of new at rails, currently using version 3.23 and I am trying to enable 'sort' on two columns in my table. I managed to create the links on these column headers and actually got one column working/sorting!But couldnt achieve the same result when I modified my code in the movie controller rb, my code can only work for one column! is:
def index
@movies = Movie.all.sort_by { |movie| movie.title }
end
Works perfectly, but when I combine another parameter i.e. release date I get an error!
def index
@movies = Movie.all.sort_by { |movie| movie.title } then { |release date| release.date}
end
Can someone please help me resolve this issue? I have researched it on google but I've gotten nothing conclusive!. Any help will be most appreciated.
[movie.title, movie.release.date]or whateverreleaseactually is. You're not "combining" anything, you're using random syntactic expressions instead of searching the web for sort_by multiple fields, which turns up things like stackoverflow.com/questions/17076372/…. Arguably you'd be better served by sorting on the DB side instead of getting all the movies and sorting in Ruby, though.