开发者

SImple_form_for in Rails 3.0 association select edit label

开发者 https://www.devze.com 2023-02-22 02:19 出处:网络
I have a model RESOURCE. It have Association with Allocation. I am using Simple_form_for gem .I want display Resource name and his role to identify it uniquely in myu resource_vteam_allocation form. I

I have a model RESOURCE. It have Association with Allocation. I am using Simple_form_for gem .I want display Resource name and his role to identify it uniquely in myu resource_vteam_allocation form. I already defined title method in resource in a hope resource will use title value but in vain. So kindly tell me what sort of changes do i need in this statement <%= f.association :resource, :required=>:true,:collection=>@selected_resource %> to show associated resource values with there 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 < ActiveRecord::Base belongs_to :resource

end

<%= simple_form_for([@resource_vteam_allocation.vteam, @resource_vteam_allocation],:r开发者_StackOverflow社区emote=>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>


:label_method =>:title is a solution of my question title method was already define in model

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号