Hi,
I have 2 models, user and project.
When I edit my profile I wan't to check the projects I wan't to follow.
So here is my code:
<% form_for @user do |f| %>
...
<% for project in @projects %>
<% fields_for "user[project_attributes][]", project do
|project_form| %>
<li>
<%= project_form.check_box "checked", {:checked =>
@user.project_ids.include?(project.id)} %><label><%= project.name
%></label>
</li>
<% end %>
<% end %>
...
<% end %>
I think the form is correct but the model and controller part is not
very clear...
Here is the log:
"user"=>{"project_attributes"=>{"1"=>{"checked"=>"1"},
"2"=>{"checked"=>"1"}, "3"=>{"checked"=>"0"}, "4"=>{"checked"=>"0"},
"5"=>{"checked"=>"0"}}, "password_confirmation"=>"[FILTERED]",
"password"=>"[FILTERED]"
The project_attributes is really messy and I have to parse the hash to
get selected projects.
There must be a cleaner way??
Greg
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment