Hello,
I have a roles table, permissions table and a rights join table. I
have has_many :through relationships between the two tables.
Roles Permissions Rights table
id name id name role_id permission_id
1 User 1 posts/new 1 2
2 Admin 2 posts/create 2 2
In the admin side of the app I create new roles and permissions. But I
wanted to be able to assign values to the rights table in an easy way,
so I created a rights controller and a view to show the current values
and assign new permission to certain roles via checkboxes.
Permissions User Admin
posts/new
posts/edit
posts/destroy
posts/create
I have some code on my view where I save the permission_ids selected
onto a hash, but I’ll like to save the roles_ids too. How can I post
both of them to save them later on the controller in the rights table?
The problem that I have is that I can post a hash of permission_ids,
but I also need the role_ids hash. The examples I have looked at only
need to post one hash and the other value needed to fill the join
table is the current_user id. In this case I need permission and role
ids. Any ideas on how to post this values into the controller?
Portion of my view
<% for permission in Permission.find(:all, :order => "name ASC")
%>
<tr class=<%= cycle(‘even’,‘odd’) %>>
<% for role in Role.find(:all) %>
<td><%= check_box_tag "right[permission_ids][]",
permission.id, permission.roles.include?(role) %>
<% end %>
<% end %>
Thanks!
Elioncho