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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
This is the sort of question you should post to the regular Rails email list, not here. This core list is about development of the framework, not how to use it. That said, you should drop the multiple habtms and look at creating a threeway join model, something like a Capability that represents the right concept as a concrete entity. You should now take this to rubyonrails-talk@googlegroups.com cheers, --josh On Jan 15, 2009, at 12:47 AM, DJ wrote:> > 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-- Josh Susser http://blog.hasmanythrough.com --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---