Class: Adminable::ResourcesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Adminable::ResourcesController
- Defined in:
- app/controllers/adminable/resources_controller.rb
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 |
Instance Method Details
#create ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/adminable/resources_controller.rb', line 40 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
68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/adminable/resources_controller.rb', line 68 def destroy @entry.destroy redirect_to polymorphic_path(@resource.model), notice: t( 'adminable.resources.deleted', resource: @resource.model.model_name.human ) end |
#edit ⇒ Object
36 37 |
# File 'app/controllers/adminable/resources_controller.rb', line 36 def edit end |
#index ⇒ Object
24 25 26 27 28 29 30 |
# File 'app/controllers/adminable/resources_controller.rb', line 24 def index @q = @resource.model.ransack(params[:q]) @entries = Adminable::Presenters::Entries.new( @q.result.includes(*includes).order(id: :desc) .page(params[:page]).per(25) ) end |
#new ⇒ Object
32 33 34 |
# File 'app/controllers/adminable/resources_controller.rb', line 32 def new @entry = @resource.model.new end |
#update ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/adminable/resources_controller.rb', line 55 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 |