Wednesday, 7 August 2013

Ruby on Rails - use :order with find_by_id

Ruby on Rails - use :order with find_by_id

In my Rails app I have a device and a device_port class with a one to many
relationship.
In my device controller I get a list of all the ports belonging to that
device but I can't seem to order them:
@device_ports = Device.find_by_id(params[:id], :order => 'id
ASC').device_ports
This doesn't seem to work and doesn't give any syntax errors either.
In the view I am simply doing:
<% @device_ports.each do |device_port| %>
...
<% end %>
Is anyone able to explain why the ports aren't being sorted by id?

No comments:

Post a Comment