Class: Upmin::ModelsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Upmin::ModelsController
- Defined in:
- app/controllers/upmin/models_controller.rb
Instance Method Summary collapse
- #action ⇒ Object
- #dashboard ⇒ Object
- #search ⇒ Object
-
#show ⇒ Object
GET /:model_name/:id.
-
#update ⇒ Object
PUT /:model_name/:id.
Instance Method Details
#action ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'app/controllers/upmin/models_controller.rb', line 51 def action # begin response = @model.perform_action(params[:method], @arguments) flash[:notice] = "Action successfully performed with a response of: #{response}" redirect_to(upmin_model_path(@model.path_hash)) # rescue Exception => e # flash.now[:alert] = "Action failed with the error message: #{e.message}" # render(:show) # end end |
#dashboard ⇒ Object
13 14 |
# File 'app/controllers/upmin/models_controller.rb', line 13 def dashboard end |
#search ⇒ Object
46 47 48 49 |
# File 'app/controllers/upmin/models_controller.rb', line 46 def search @q = @klass.ransack(params[:q]) @results = Upmin::Paginator.paginate(@q.result(distinct: true), @page, 30) end |
#show ⇒ Object
GET /:model_name/:id
17 18 |
# File 'app/controllers/upmin/models_controller.rb', line 17 def show end |
#update ⇒ Object
PUT /:model_name/:id
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/controllers/upmin/models_controller.rb', line 21 def update instance = @model.instance updates = params[@klass.name.underscore] transforms = updates.delete(:transforms) || {} updates.each do |key, value| # TODO(jon): Figure out a better way to do transforms. # This could cause issues and is exploitable, but it # should be fine for now since this is only on admin pages if transforms[key] and not value.blank? value = transform(transforms, key, value) end instance.send("#{key}=", value) end if instance.save flash[:notice] = "#{@klass.humanized_name(:singular)} updated successfully." redirect_to(upmin_model_path(@model.path_hash)) else flash.now[:alert] = "#{@klass.humanized_name(:singular)} was NOT updated." render(:show) end end |