2011-04-04 30 views
0

我有一個模型RESOURCE。它與分配有關聯。我正在使用Simple_form_for gem。我希望顯示資源名稱和他的角色,以在myu resource_vteam_allocation表單中唯一標識它。我已經在資源中定義了標題方法,希望資源將使用標題值但徒勞無功。所以,請你告訴我我需要在此聲明<%= f.association :resource, :required=>:true,:collection=>@selected_resource %>什麼樣的變化,以顯示相關的資源價值與存在RESOURCE_TYPESImple_form_for在Rails 3.0關聯選擇編輯標籤

class Resource < ActiveRecord::Base 
    belongs_to :resource_type 
    has_many :resource_vteam_allocation, :dependent => :destroy 
    has_many :vteams, :through => :resource_vteam_allocation 
    accepts_nested_attributes_for :resource_vteam_allocation, :allow_destroy => true 
    def title 
    "#{name} #{resource_type.title}" 
    end 
end 

類ResourceVteamAllocation <的ActiveRecord :: Base的 belongs_to的:資源

<%= simple_form_for([@resource_vteam_allocation.vteam, @resource_vteam_allocation],:remote=>true, :html=>{:multipart=>true}) do |f| %> 
    <%= f.error_notification %> 
    <div class="inputs"> 
     <%= f.association :resource, :required=>:true,:collection=>@selected_resource %> 
     <%= f.input :resource_type, :required=>:true, :label=>"Joining As" %> 
     <%= f.association :resource_billing_type, :required=>:true, :label=>"Billing Type" %> 
    </div> 
    <div class="actions" > 
    <%= f.button :submit, :class=>'button big' %> <span style="vertical-align: bottom">or</span> <%= link_to "Cancel", "#", :id=>'new-xdoc-cancel' %> 
    <% end %> 
</div> 

回答

0

:label_method =>:title是我的問題的解決方案標題方法已在模型中定義

<%= f.association :resource, :required=>:true,:collection=>@selected_resource, :label_method=>:title %>