Class: Admin::UsersController
- Inherits:
-
BaseController
- Object
- BaseController
- Admin::UsersController
- Defined in:
- app/controllers/admin/users_controller.rb
Instance Method Summary collapse
- #activate ⇒ Object
- #create ⇒ Object
-
#destroy ⇒ Object
Remotly Destroy an User return the list of all users.
- #edit ⇒ Object
-
#export_newsletter ⇒ Object
example action to return the contents of a table in CSV format.
-
#filter ⇒ Object
Filter users by something, only by gender & country for the moment.
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#activate ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/controllers/admin/users_controller.rb', line 59 def activate unless @user.active? if @user.activate flash[:notice] = I18n.t('user.activation.success').capitalize else flash[:error] = I18n.t('user.activation.failed').capitalize end else if @user.disactivate flash[:notice] = I18n.t('user.disactivation.success').capitalize else flash[:error] = I18n.t('user.disactivation.failed').capitalize end end respond_to do |wants| wants.html do redirect_to(:back) end wants.js end end |
#create ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/admin/users_controller.rb', line 21 def create if @user.save flash[:notice] = I18n.t('user.create.success').capitalize redirect_to([forgeos_core, :edit, :admin, @user]) else flash[:error] = I18n.t('user.create.failed').capitalize render :action => 'new' end end |
#destroy ⇒ Object
Remotly Destroy an User return the list of all users
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/admin/users_controller.rb', line 45 def destroy if @user.destroy flash[:notice] = I18n.t('user.destroy.success').capitalize else flash[:error] = I18n.t('user.destroy.failed').capitalize end respond_to do |wants| wants.html do redirect_to([forgeos_core, :admin, :users]) end wants.js end end |
#edit ⇒ Object
31 32 |
# File 'app/controllers/admin/users_controller.rb', line 31 def edit end |
#export_newsletter ⇒ Object
example action to return the contents of a table in CSV format
83 84 85 86 87 88 89 90 91 92 |
# File 'app/controllers/admin/users_controller.rb', line 83 def require 'fastercsv' return flash[:error] = I18n.t('user.export.failed').capitalize if @users.empty? stream_csv do |csv| csv << %w[name email] @users.each do |u| csv << [u.fullname,u.email] end end end |
#filter ⇒ Object
Filter users by something, only by gender & country for the moment
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/controllers/admin/users_controller.rb', line 95 def filter return redirect_to(:action => 'index') unless params[:filter] @gender = params[:filter][:gender] @country = params[:filter][:country] @v_age = params[:filter][:age][:values].to_i @c_age = params[:filter][:age][:conds] gender = @gender.chomp.split(',').collect(&:to_i) conditions_ini = {} conditions_ini[:civility] = gender unless @country.blank? conditions_ini[:country_id] = @country.to_i end unless @v_age.nil? && @c_age.nil? old_date = (Date.today << @v_age*12) case @c_age when '==' conditions_ini[:birthday] = old_date.ago(12.month)..old_date when '!=' conditions_ini[:birthday_not] = old_date.ago(12.month)..old_date when '>=' conditions_ini[:birthday_lte] = old_date when '<=' conditions_ini[:birthday_gte] = old_date when '<' conditions_ini[:birthday_gt] = old_date when '>' conditions_ini[:birthday_lt] = old_date end end @users = User.all( :conditions => conditions_ini ) flash[:error] = I18n.t('user.search.failed').capitalize if @users.empty? return if params[:commit] == I18n.t('export').capitalize render :template => 'admin/users/index' end |
#index ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'app/controllers/admin/users_controller.rb', line 5 def index respond_to do |format| format.html format.json do sort render :layout => false end end end |
#new ⇒ Object
18 19 |
# File 'app/controllers/admin/users_controller.rb', line 18 def new end |
#show ⇒ Object
15 16 |
# File 'app/controllers/admin/users_controller.rb', line 15 def show end |
#update ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'app/controllers/admin/users_controller.rb', line 34 def update if @user.update_attributes(params[:user]) flash[:notice] = I18n.t('user.update.success').capitalize else flash[:error] = I18n.t('user.update.failed').capitalize end render :action => 'edit' end |