Hi
Group Members
I am trying to show check-boxes along with
their state in the views in a three models user, role and permission.
My Models are like following
class User < ActiveRecord::Base
has_and_belongs_to_many :roles, :join_table
=> :roles_users_permissions
has_and_belongs_to_many :permissions, :join_table
=> :roles_users_permissions
end
class Permission < ActiveRecord::Base
has_and_belongs_to_many :roles, :join_table
=> :roles_users_permissions
has_and_belongs_to_many :users, :join_table
=> :roles_users_permissions
end
class Role < ActiveRecord::Base
has_and_belongs_to_many :users, :join_table
=> :roles_users_permissions
has_and_belongs_to_many :permissions, :join_table
=> :roles_users_permissions
end
Now from users view (show.html.erb) i am generating check boxes for
all the roles/permissions that a user have like ->
<% for role in Role.find(:all) %>
<div>
<input type="checkbox" id="<%= role.id %>" name="role_ids[]"
value="<%= role.id %>" <% if @user.roles.include? role
%>checked="checked" <%end%> > <%=role.name%>
<% for permission in Permission.find(:all) %>
<input type="checkbox" id="<%= permission.id %>"
name="permission_ids[]" value="<%= permission.id %>" <% if
@user.roles.include? permission %>checked="checked" <%end%> > <
%=permission.permission_name%>
<% end %>
</div>
<% end %>
In users controller the show section is like->
def show
@user = User.find(params[:id])
@roles = Role.find(:all)
@permissions = Permission.find(:all)
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @user }
end
end
The above code fetched the roles and their state correctly but all
the permission check boxes are unchecked though in the table its
there. What am i missing? Needs to write something more on controller?
Any suggestions will nively appreciated.
DJ
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---