Сортировка выбора в Ruby On Rails - PullRequest
1 голос
/ 21 октября 2010

ROR newby question:

У меня есть контроллер со следующим действием:

# 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

и выбор в организации / новое представление для типа организации, например:

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

Я пытаюсь упорядочить выбор по типу организации.Как бы я это сделал?

Спасибо за ваше время

Sniffer

Ответы [ 2 ]

2 голосов
/ 22 октября 2010

Попробуйте:

<%= 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 } %>
0 голосов
/ 21 октября 2010

Попробуйте:

Organisationtype.find(:all).sort{ |a,b| a.title <=> b.title }.collect... 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...