I am using Rails 3.0, Ruby 1.9.2 and the Plataformatec simple_form gem. This code works with a form_for but not simple_form_for:
<%= simple_form_for(@provider) do |f| %>
<% Car.all.each do |c| %>
<div>
<%= check_box_tag :car_ids, c.id, @store.cars.include?(c), :name => 'store[car_ids][]' %>
$<%= c.cost %> | <%= c.description %>
</div>
<% end %>
<div class="actions">
<%= f.submit "New" %>
</div>
<% end %>
How do I get it to work with simple_form_for?
Thanks in advance!
The problem was in the controller code.
In the “new” controller action I can’t simply perform:
as one would normally.
Instead I have to process each parameter separately:
@provider.location = params[:provider][:location]
etc…
For the Car check boxes, I add each car_id from the car_ids parameter to the “has_many” cars model association one at a time:
Then I can call:
And it saves correctly (my initial problem was that it wasn’t saving the selected Cars).
For some reason, I was able to figure this out only after posting the question here. Funny how that works.
Thanks all for your replies!