views:

12

answers:

2

Hi

ROR newby question:

I've got a controller with the following action:

# GET /organisations/new
# GET /organisations/new.xml
def new
  @organisation = Organisation.new
  @organisationtypes = Organisationtype.find(:all) 

  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @organisation }
  end
end

and a select within the organisations/new view for organisationtype like so:

<p>
<%= f.label :organisationtype %><br />
<%= select "organisation", "organisationtype_id", Organisationtype.find(:all).collect {|p| [ p.organisationtype, p.id ] }, {:include_blank => true } %>
</p>

I'm struggling to order the select by organisationtype. How would I do this?

Thanks for your time

Sniffer

A: 

Try it with:

Organisationtype.find(:all).sort{ |a,b| a.title <=> b.title }.collect... 
Lichtamberg
+2  A: 

Try it with:

<%= select "organisation", "organisationtype_id", Organisationtype.find(:all,:order => "organisationtype DESC").collect {|p| [ p.organisationtype, p.id ] }, {:include_blank => true } %>

OR

<%= select "organisation", "organisationtype_id", Organisationtype.find(:all,:order => "organisationtype ASC").collect {|p| [ p.organisationtype, p.id ] }, {:include_blank => true } %>
krunal shah