Class: ProfilesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ProfilesController
- Defined in:
- app/controllers/profiles_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /profiles POST /profiles.json.
-
#destroy ⇒ Object
DELETE /profiles/1 DELETE /profiles/1.json.
-
#edit ⇒ Object
GET /profiles/1/edit.
-
#index ⇒ Object
GET /profiles GET /profiles.json.
-
#new ⇒ Object
GET /profiles/new.
-
#show ⇒ Object
GET /profiles/1 GET /profiles/1.json.
-
#update ⇒ Object
PUT /profiles/1 PUT /profiles/1.json.
Instance Method Details
#create ⇒ Object
POST /profiles POST /profiles.json
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 |
# File 'app/controllers/profiles_controller.rb', line 106 def create if current_user.has_role?('Librarian') @profile = Profile.new(profile_params) if @profile.user password = @profile.user.set_auto_generated_password end else @profile = Profile.new(profile_params) end respond_to do |format| if @profile.save if @profile.user @profile.user.role = Role.find_by(name: 'User') flash[:temporary_password] = password end format.html { redirect_to @profile, notice: t('controller.successfully_created', model: t('activerecord.models.profile')) } format.json { render json: @profile, status: :created, location: @profile } else format.html { render action: "new" } format.json { render json: @profile.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /profiles/1 DELETE /profiles/1.json
157 158 159 160 161 162 163 164 |
# File 'app/controllers/profiles_controller.rb', line 157 def destroy @profile.destroy respond_to do |format| format.html { redirect_to profiles_url, notice: t('controller.successfully_deleted', model: t('activerecord.models.profile')) } format.json { head :no_content } end end |
#edit ⇒ Object
GET /profiles/1/edit
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/controllers/profiles_controller.rb', line 83 def edit if defined?(EnjuCirculation) if params[:mode] == 'feed_token' if params[:disable] == 'true' @profile.delete_checkout_icalendar_token else @profile.reset_checkout_icalendar_token end render partial: 'feed_token', locals: {profile: @profile} return end end if @profile.user == current_user redirect_to edit_my_account_url return end if @profile.user.try(:locked_at?) @profile.user.locked = true end end |
#index ⇒ Object
GET /profiles GET /profiles.json
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/profiles_controller.rb', line 9 def index if params[:username].present? profile = User.find_by(username: params[:username]).try(:profile) if profile redirect_to profile return end end query = flash[:query] = params[:query].to_s @query = query.dup @count = {} sort = {sort_by: 'created_at', order: 'desc'} case params[:sort_by] when 'username' sort[:sort_by] = 'username' end case params[:order] when 'asc' sort[:order] = 'asc' when 'desc' sort[:order] = 'desc' end query = params[:query] page = params[:page] || 1 role = current_user.try(:role) || Role.default_role search = Profile.search search.build do fulltext query if query with(:required_role_id).less_than_or_equal_to role.id order_by sort[:sort_by], sort[:order] end search.query.paginate(page.to_i, Profile.default_per_page) @profiles = search.execute!.results @count[:query_result] = @profiles.total_entries respond_to do |format| format.html # index.html.erb format.json { render json: @profiles } end end |
#new ⇒ Object
GET /profiles/new
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/profiles_controller.rb', line 69 def new @profile = Profile.new @profile.user = User.new @profile.user_group = current_user.profile.user_group @profile.library = current_user.profile.library @profile.locale = current_user.profile.locale respond_to do |format| format.html # new.html.erb format.json { render json: @profile } end end |
#show ⇒ Object
GET /profiles/1 GET /profiles/1.json
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/profiles_controller.rb', line 55 def show if @profile.user == current_user redirect_to my_account_url return end respond_to do |format| format.html # show.html.erb format.html.phone format.json { render json: @profile } end end |
#update ⇒ Object
PUT /profiles/1 PUT /profiles/1.json
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'app/controllers/profiles_controller.rb', line 134 def update @profile.update(profile_update_params) if @profile.user if @profile.user.auto_generated_password == "1" password = @profile.user.set_auto_generated_password end end respond_to do |format| if @profile.save flash[:temporary_password] = password format.html { redirect_to @profile, notice: t('controller.successfully_updated', model: t('activerecord.models.profile')) } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @profile.errors, status: :unprocessable_entity } end end end |