我有一个模型资源。它与分配有关联。我正在使用 Simple_form_for gem 。我想显示资源名称和他的角色以在 myu resource_vteam_allocation 表单中唯一标识它。我已经在资源中定义了标题方法,希望资源将使用标题值但徒劳无功。所以请告诉我在这个语句中我需要什么样的改变<%= f.association :resource, :required=>:true,:collection=>@selected_resource %>
来显示与资源类型相关的资源值
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 :resource
结尾
<%= 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>