Rails 3.0关联中的SImple_form_for选择编辑标签

时间:2011-04-04 12:37:34

标签: ruby-on-rails ruby-on-rails-3 rubygems simple-form

我有一个模型RESOURCE。它有协调分配。我正在使用Simple_form_for gem。我希望显示资源名称和他的角色,以myu resource_vteam_allocation形式唯一地标识它。我已经在资源中定义了一个希望资源中的title方法将使用标题值但是徒劳无功。请告诉我在此语句<%= f.association :resource, :required=>:true,:collection=>@selected_resource %>中需要进行哪些更改以显示与resource_type相关的资源值

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

class ResourceVteamAllocation&lt;的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>

1 个答案:

答案 0 :(得分:0)

:label_method =>:title是我的问题标题方法的解决方案已在模型中定义

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