Class: Adminable::ResourcesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Adminable::ResourcesController
- Defined in:
- app/controllers/adminable/resources_controller.rb
Class Method Summary collapse
-
.set_attributes ⇒ Object
Calls from children controller class to manage resource attributes.
Instance Method Summary collapse
-
#create ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize.
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
-
#initialize ⇒ ResourcesController
constructor
A new instance of ResourcesController.
- #new ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize ⇒ ResourcesController
Returns a new instance of ResourcesController.
3 4 5 6 7 8 9 |
# File 'app/controllers/adminable/resources_controller.rb', line 3 def initialize(*) @resource = Adminable::Configuration.resources.find do |resource| resource == Adminable::Resource.new(resource_model_name) end super end |
Class Method Details
.set_attributes ⇒ Object
Calls from children controller class to manage resource attributes
97 98 99 100 101 |
# File 'app/controllers/adminable/resources_controller.rb', line 97 def self.set_attributes before_action do @resource.attributes.configure { yield(@resource.attributes) } end end |
Instance Method Details
#create ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/adminable/resources_controller.rb', line 39 def create @entry = @resource.model.new(resource_params) if @entry.save redirect_to polymorphic_path(@resource.model), notice: t( 'adminable.resources.created', resource: @resource.model.model_name.human ) else flash.now[:alert] = @entry.errors..first render :new end end |
#destroy ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/adminable/resources_controller.rb', line 67 def destroy @entry.destroy redirect_to polymorphic_path(@resource.model), notice: t( 'adminable.resources.deleted', resource: @resource.model.model_name.human ) end |
#edit ⇒ Object
35 36 |
# File 'app/controllers/adminable/resources_controller.rb', line 35 def edit end |
#index ⇒ Object
23 24 25 26 27 28 29 |
# File 'app/controllers/adminable/resources_controller.rb', line 23 def index @q = @resource.model.ransack(params[:q]) @entries = Adminable::Presenters::Entries.new( @q.result.includes(*@resource.includes).order(id: :desc) .page(params[:page]).per(25) ) end |
#new ⇒ Object
31 32 33 |
# File 'app/controllers/adminable/resources_controller.rb', line 31 def new @entry = @resource.model.new end |
#update ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/adminable/resources_controller.rb', line 54 def update if @entry.update(resource_params) redirect_to polymorphic_path(@resource.model), notice: t( 'adminable.resources.updated', resource: @resource.model.model_name.human ) else flash.now[:alert] = @entry.errors..first render :edit end end |