Class: Madmin::ResourcesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- BaseController
- ApplicationController
- Madmin::ResourcesController
- Includes:
- ActiveSupport::Inflector
- Defined in:
- app/controllers/madmin/resources_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
38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/madmin/resources_controller.rb', line 38 def create @resource = ResourceDecorator.new(resource.new(resource_params)) if @resource.save redirect_to resource_path(id: @resource.id) else render :new end end |
#destroy ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'app/controllers/madmin/resources_controller.rb', line 59 def destroy if @resource.destroy redirect_to resources_path(params[:resource]) else flash[:error] = "There was an issue deleting the record." redirect_to :back end end |
#edit ⇒ Object
48 49 |
# File 'app/controllers/madmin/resources_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 |
# File 'app/controllers/madmin/resources_controller.rb', line 11 def index @scopes = madmin_resource.scopes @headers = madmin_resource.index_headers if params[:scope]&.to_sym&.in?(@scopes) begin @collection = resource.send(params[:scope]) rescue ArgumentError raise ScopeWithArgumentsError, "The scope #{params[:scope.to_sym]} on #{resource.name} takes arguments, which are currently unsupported." end else @collection = resource.all end respond_to do |format| format.html format.json { render json: @collection.map { |c| {id: c.id, display_value: c.title} } } end end |
#new ⇒ Object
34 35 36 |
# File 'app/controllers/madmin/resources_controller.rb', line 34 def new @resource = ResourceDecorator.new(resource.new(resource_params)) end |
#show ⇒ Object
31 32 |
# File 'app/controllers/madmin/resources_controller.rb', line 31 def show end |
#update ⇒ Object
51 52 53 54 55 56 57 |
# File 'app/controllers/madmin/resources_controller.rb', line 51 def update if @resource.update(resource_params) redirect_to resource_path(id: @resource.id) else render :edit end end |