Class: Adminka::CrudController
- Inherits:
-
AdminController
- Object
- ActionController::Base
- AdminController
- Adminka::CrudController
- Includes:
- Staff
- Defined in:
- app/controllers/adminka/crud_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
-
#initialize ⇒ CrudController
constructor
A new instance of CrudController.
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Methods included from Staff
Constructor Details
#initialize ⇒ CrudController
Returns a new instance of CrudController.
7 8 9 10 11 |
# File 'app/controllers/adminka/crud_controller.rb', line 7 def initialize super @config = @menu[self.class::MODEL.downcase] @model = Object.const_get(self.class::MODEL) end |
Instance Method Details
#create ⇒ Object
18 19 20 21 22 23 |
# File 'app/controllers/adminka/crud_controller.rb', line 18 def create @entity = @model.new(entity_params) return render :new unless @entity.save flash[:notice] = t('adminka.create') redirect_to @entity end |
#destroy ⇒ Object
47 48 49 50 51 |
# File 'app/controllers/adminka/crud_controller.rb', line 47 def destroy @model.find(params[:id]).destroy flash[:notice] = t('adminka.delete') redirect_to adminka.send("#{@model.to_s.downcase.pluralize}_path") end |
#edit ⇒ Object
33 34 35 |
# File 'app/controllers/adminka/crud_controller.rb', line 33 def edit @entity = @model.select(select_fields('edit')).find(params[:id]) end |
#index ⇒ Object
13 14 15 16 |
# File 'app/controllers/adminka/crud_controller.rb', line 13 def index @q = @model.ransack(params[:q]) @entities = @q.result.select(select_fields('list')).page(params[:page]) end |
#new ⇒ Object
25 26 27 |
# File 'app/controllers/adminka/crud_controller.rb', line 25 def new @entity = @model.new end |
#show ⇒ Object
29 30 31 |
# File 'app/controllers/adminka/crud_controller.rb', line 29 def show @entity = @model.select(select_fields('show')).find(params[:id]) end |
#update ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/adminka/crud_controller.rb', line 37 def update @entity = @model.find(params[:id]) if @entity.update(entity_params) flash[:notice] = t('adminka.update') redirect_to @entity else render :edit end end |