Class: Gluttonberg::Admin::Settings::UsersController
- Inherits:
-
BaseController
- Object
- ActionController::Base
- BaseController
- Gluttonberg::Admin::Settings::UsersController
- Defined in:
- app/controllers/gluttonberg/admin/settings/users_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/gluttonberg/admin/settings/users_controller.rb', line 36 def create role = params[:user].delete(:role) unless params[:user].blank? @user = User.new(params[:user]) @user.role = role if current_user.user_valid_roles(@user).include?(role) if @user.save flash[:notice] = "Account registered!" redirect_to admin_users_path else render :action => :new end end |
#delete ⇒ Object
67 68 69 70 71 72 73 |
# File 'app/controllers/gluttonberg/admin/settings/users_controller.rb', line 67 def delete display_delete_confirmation( :title => "Delete “#{@user.email}” user?", :url => admin_user_path(@user), :return_url => admin_users_path ) end |
#destroy ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'app/controllers/gluttonberg/admin/settings/users_controller.rb', line 75 def destroy if @user.destroy flash[:notice] = "Account deleted!" redirect_to admin_users_path else flash[:error] = "There was an error deleting the account." redirect_to admin_users_path end end |
#edit ⇒ Object
48 49 |
# File 'app/controllers/gluttonberg/admin/settings/users_controller.rb', line 48 def edit end |
#index ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/controllers/gluttonberg/admin/settings/users_controller.rb', line 11 def index unless current_user.super_admin? || current_user.admin? redirect_to :action => "edit" , :id => current_user.id end if current_user.super_admin? unless params[:query].blank? @users = User.order(get_order).where("first_name LIKE '%#{params[:query]}%' OR last_name LIKE '%#{params[:query]}%' OR email LIKE '%#{params[:query]}%' OR bio LIKE '%#{params[:query]}%' " ) else @users = User.order(get_order) end else unless params[:query].blank? @users = User.order(get_order).where("role != 'super_admin' AND (first_name LIKE '%#{params[:query]}%' OR last_name LIKE '%#{params[:query]}%' OR email LIKE '%#{params[:query]}%' OR bio LIKE '%#{params[:query]}%' )" ) else @users = User.order(get_order).where( ["role != ?" , "super_admin"]) end end @users = @users.paginate(:page => params[:page] , :per_page => Gluttonberg::Setting.get_setting("number_of_per_page_items") ) end |
#new ⇒ Object
32 33 34 |
# File 'app/controllers/gluttonberg/admin/settings/users_controller.rb', line 32 def new @user = User.new end |
#update ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/gluttonberg/admin/settings/users_controller.rb', line 51 def update role = params[:user].delete(:role) unless params[:user].blank? @user.role = role if current_user.user_valid_roles(@user).include?(role) if @user.update_attributes(params[:user]) flash[:notice] = "Account updated!" if current_user.super_admin? || current_user.admin? redirect_to admin_users_path else redirect_to :action => :edit end else flash[:notice] = "Failed to save account changes!" render :action => :edit end end |