I have two models, Developers and Tasks,
class Developer < ActiveRecord::Base
attr_accessible :address, :comment, :email, :name, :nit, :phone, :web
has_many :assignments
has_many :tasks, :through => :assignments
end
class Task < ActiveRecord::Base
attr_accessible :description, :name, :sprint_id, :developer_ids
has_many :assignments
has_many :developers, :through => :assignments
end
class Assignment < ActiveRecord::Base
attr_accessible :accomplished_time, :developer_id, :estimated_time, :status, :task_id
belongs_to :task
belongs_to :developer
end
im taking care of the relation by adding an Assignment table, so i can add many developers to one task in particular, now i would also like to be able to manipulate the other fields i added to the joining table like the ‘estimated_time’, ‘accomplished_time’… etc… what i got on my Simple_form is
`
<%= simple_form_for [@sprint,@task], :html => { :class => 'form-horizontal' } do |f| %>
<%= f.input :name %>
<%= f.input :description %>
<%= f.association :developers, :as => :check_boxes %>
<div class="form-actions">
<%= f.button :submit, :class => 'btn-primary' %>
<%= link_to t('.cancel', :default => t("helpers.links.cancel")),
project_sprint_path(@sprint.project_id,@sprint), :class => 'btn' %>
</div>
<% end %>`
This only allows me to select the developers, i want to be able to modify the estimated_time field right there.
Any Suggestions?
I love how simple-form has the association helpers, making it really easy in some cases. Unfortunately, what you want you cannot solve with just simple-form.
You will have to create
assignmentsfor this to work.There are two possible approaches.
For both you will have to add the following to your model:
Note that if you are using
attr_accesible, you should also addassignments_attributesto it.The easy approach
Suppose you know how many assignments, maximally, a
taskwould have. Suppose 1 for simplicity.In your controller, write
This will make sure there is one new assignment.
In your view write:
The problem with this approach: what if you want more than 1, 2 or 3?
Use cocoon
Cocoon is a gem that allows you to create dynamic nested forms.
Your view would become:
And define a partial
_assignment_fields.html.haml:Hope this helps.