Class: Admin::RolesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Admin::RolesController
- Defined in:
- app/controllers/admin/roles_controller.rb
Instance Method Summary collapse
- #add_user ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #remove_user ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
- #users ⇒ Object
Instance Method Details
#add_user ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'app/controllers/admin/roles_controller.rb', line 70 def add_user role = Role.find(params[:role_id]) user = User.find(params[:id]) if role.users << user render :json => {:status => "Ok", :role_id => role.id, :user_id => user.id }.to_json else render :json => {:status => "Error", :user_id => user.id }.to_json end end |
#create ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'app/controllers/admin/roles_controller.rb', line 31 def create @role = Role.new(params[:role]) @role.save! redirect_to admin_roles_path rescue ActiveRecord::RecordInvalid => invalid flash[:error] = invalid.record.errors. render :action => :index end |
#destroy ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'app/controllers/admin/roles_controller.rb', line 40 def destroy @role = Role.find(params[:id]) @role.destroy unless @role.standard? redirect_to admin_roles_path() rescue ActiveRecord::RecordNotFound flash[:error] = 'The specified Role could not be found.' redirect_to :action => :index end |
#edit ⇒ Object
16 17 18 |
# File 'app/controllers/admin/roles_controller.rb', line 16 def edit end |
#index ⇒ Object
7 8 9 10 |
# File 'app/controllers/admin/roles_controller.rb', line 7 def index @roles = Role.find(:all) @role = Role.new end |
#new ⇒ Object
19 20 21 |
# File 'app/controllers/admin/roles_controller.rb', line 19 def new end |
#remove_user ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'app/controllers/admin/roles_controller.rb', line 81 def remove_user role = Role.find(params[:role_id]) user = User.find(params[:id]) if role.remove_user(user) render :json => {:status => "Ok", :role_id => role.id, :user_id => user.id }.to_json else render :json => {:status => "Error", :user_id => user.id }.to_json end end |
#show ⇒ Object
12 13 14 |
# File 'app/controllers/admin/roles_controller.rb', line 12 def show @role = Role.find(params[:id]) end |
#update ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'app/controllers/admin/roles_controller.rb', line 22 def update @role = Role.find(params[:id]) if @role.update_attributes(params[:role]) redirect_to admin_role_path(@role) else render :action => 'show' end end |
#users ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/admin/roles_controller.rb', line 49 def users role = Role.find(params[:role_id]) available_users = User.find(:all, :conditions => ['id NOT IN (SELECT user_id FROM roles_users WHERE role_id = ?)', role.id]) taken_users = role.users result = {:available => [], :taken => []} available_users.each do | usr | result[:available] << [usr.id, usr.name] end taken_users.each do | usr | result[:taken] << [usr.id, usr.name] end respond_to do |format| format.js { render :json => result.to_json } end end |