0

I am building an application in which when the user log in as an admin it will have the list of registered users and have four links show,edit destroy and settings.What i want is when the admin click on the settings link it will have the view of check boxes in which admin decides the permission of users to read,edit,create and destroy of the model available in an application.

Thanks in advance.

Mohd Anas
  • 634
  • 1
  • 9
  • 22

1 Answers1

0

If I understand you correctly you are looking for a view that sets the settings for one user.

Since you didn't give any details on your model I'll assume the Model is called User and the permissions are just boolean fields on that model.

Similar to this:

User
 - can_read
 - can_create
 - can_destroy
 - can_edit

I would then implement the view like this:

<%= form_for @user do |f| %>
  <%= flabel :can_read %>
  <%= f.check_box :can_read %>

  <%= flabel :can_create %>
  <%= f.check_box :can_create %>

  ....

  <%= f.submit %>
<% end %>

Or shorter:

<%= form_for @user do |f| %>
  <% [:can_read, :can_create, :can_edit, :can_delete].each do |permission| %>
    <%= flabel permission %>
    <%= f.check_box permission %>
  <% end %>


  <%= f.submit %>
<% end %>

The controller code would obviously look like this:

def edit
 @user = User.find(params[:id]
end

def update
  @user = User.find(params[:id]
  @user.update_attributes(params[:user])
end
Tigraine
  • 23,358
  • 11
  • 65
  • 110
  • sorry Tigraine for not giving the exact details....Actually permission is not a boolean variable i have a differnt model for permission which have columns object_type,action_name and decsription all are of string types. if u said i can mail you the application just let me know as soon as possible.. – Mohd Anas Oct 23 '12 at 08:57
  • and one more thing permissions are generated dynamically as the user performs some action like read create delete it will be automatically updated on the permission model... – Mohd Anas Oct 23 '12 at 08:59