Class: Tolaria::ResourceController
- Inherits:
-
TolariaController
- Object
- ApplicationController
- TolariaController
- Tolaria::ResourceController
- Defined in:
- app/controllers/tolaria/resource_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/tolaria/resource_controller.rb', line 27 def create @resource = @managed_class.klass.new @resource.assign_attributes(resource_params[@managed_class.param_key]) display_name = Tolaria.display_name(@resource) if @resource.save flash[:success] = "#{random_blingword} You created the #{@managed_class..singularize} “#{display_name}”." return redirect_to form_completion_redirect_path(@managed_class, @resource) else log_validation_errors! flash.now[:error] = "Your changes couldn’t be saved. Please correct the following errors:" return render tolaria_template("tolaria_resource/new") end end |
#destroy ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/controllers/tolaria/resource_controller.rb', line 66 def destroy @resource = @managed_class.klass.find_by_id(params[:id]) or raise ActiveRecord::RecordNotFound display_name = Tolaria.display_name(@resource) begin @resource.destroy rescue ActiveRecord::DeleteRestrictionError => e flash[:restricted] = "You cannot delete “#{display_name}” because other items are using it." return redirect_to form_completion_redirect_path(@managed_class, @resource) end flash[:destructive] = "You deleted the #{@managed_class..singularize.downcase} “#{display_name}”." return redirect_to form_completion_redirect_path(@managed_class) end |
#edit ⇒ Object
44 45 46 47 |
# File 'app/controllers/tolaria/resource_controller.rb', line 44 def edit @resource = @managed_class.klass.find_by_id(params[:id]) or raise ActiveRecord::RecordNotFound return render tolaria_template("tolaria_resource/edit") end |
#index ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'app/controllers/tolaria/resource_controller.rb', line 5 def index @search = @managed_class.klass.ransack(ransack_params) @resources = @search.result if @managed_class.paginated? @resources = @resources.page(page_param).per(Tolaria.config.page_size) end unless currently_sorting? @resources = @resources.order(@managed_class.default_order) end return render tolaria_template("tolaria_resource/index") end |
#new ⇒ Object
22 23 24 25 |
# File 'app/controllers/tolaria/resource_controller.rb', line 22 def new @resource = @managed_class.klass.new return render tolaria_template("tolaria_resource/new") end |
#show ⇒ Object
17 18 19 20 |
# File 'app/controllers/tolaria/resource_controller.rb', line 17 def show @resource = @managed_class.klass.find_by_id(params[:id]) or raise ActiveRecord::RecordNotFound return render tolaria_template("tolaria_resource/show") end |
#update ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/tolaria/resource_controller.rb', line 49 def update @resource = @managed_class.klass.find_by_id(params[:id]) or raise ActiveRecord::RecordNotFound @resource.assign_attributes(resource_params[@managed_class.param_key]) display_name = Tolaria.display_name(@resource) if @resource.save flash[:success] = "#{random_blingword} You updated the #{@managed_class..singularize.downcase} “#{display_name}”." return redirect_to form_completion_redirect_path(@managed_class, @resource) else log_validation_errors! flash.now[:error] = "Your changes couldn’t be saved. Please correct the following errors:" return render tolaria_template("tolaria_resource/edit") end end |