I have a table with 2 columns. “car” “year”. I want to do a collect into an array of all cars and then sort them by year. How do I do that?
<% @cars_pre = Car.find(:all) %>
<% @cars = @cars_pre.collect {|x| x.car} %>
I need the steps to order the @cars array by year, keep in mind I am not keeping year values in the @cars array, just cars. Thanks in advance.
From the code sample, I’m guessing you are using Ruby on Rails. If you are, I would recommend you allow your database to order the results. For example: