I have 2 scaffolds Role(name:string), Permission(name:string) I created a relation between them. So now i can display Role's permissions in an easy way: Role.permissions.
The problem is to create a form for new Role, because in addition to the field 'name' I would like to add there a list of permissions (checkboxes).
This is what I managed to do so far. (Now I'm using a textbox instead of checkbox)
<%= form_for(@role) do |f| %>
<% if @role.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@role.errors.count, "error") %> prohibited this role from being saved:</h2>
<ul>
<% @role.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="list_of_fields">
<div class="field">
<%= text_field_tag :myVariable] %>
</div>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Precisely I'm talking about this piece of code:
<div class="list_of_fields">
<div class="field">
<%= text_field_tag :myVariable] %>
</div>
</div>
This produces:
Parameters: {"utf8"=>"â", "authenticity_token"=>"MdS0VkLAxGoZM8P71H0a9M54CpMt8DnnwSp75UVGtqE=", "role"= {"name"=>"abc"}, "myVariable"=>"xyz", "commit"=>"Create Role"}
I don't like this solution because if somebody chooses a specific name of permission it may fail ('commit' e.g.).
I would like to close all these additional fields within a hash. What's the right way to do this?