代码之家  ›  专栏  ›  技术社区  ›  Sniffer

在Ruby On Rails中对选择进行排序

  •  1
  • Sniffer  · 技术社区  · 15 年前

    ROR newby问题:

    我有一个控制器有以下动作:

    # 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
    

    以及在Organizations/new视图中选择OrganizationType,例如:

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

    谢谢你的时间

    嗅探器

    2 回复  |  直到 15 年前
        1
  •  2
  •   krunal shah    15 年前

    试试看:

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

    或者

    <%= select "organisation", "organisationtype_id", Organisationtype.find(:all,:order => "organisationtype ASC").collect {|p| [ p.organisationtype, p.id ] }, {:include_blank => true } %>
    
        2
  •  0
  •   BvuRVKyUVlViVIc7    15 年前

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