0
votes

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],: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

1 Answers

0
votes

: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 %>