Class: DryAdmin::ResourcesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- DryAdmin::ResourcesController
- Defined in:
- app/controllers/dry_admin/resources_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'app/controllers/dry_admin/resources_controller.rb', line 23 def create @record = @model.new(resource_params) if @record.save redirect_to({action: 'index'}, notice: "#{@model.name} successfully saved") else render 'new' end end |
#destroy ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'app/controllers/dry_admin/resources_controller.rb', line 49 def destroy @record = @model.find(params[:id]) if @record.destroy redirect_to({action: 'index'}, notice: "#{@model.name} successfully destroyed") else redirect_to({action: 'index'}, alert: "#{@model.name} hasn't been destroyed") end end |
#edit ⇒ Object
36 37 38 |
# File 'app/controllers/dry_admin/resources_controller.rb', line 36 def edit @record = @model.find(params[:id]) end |
#index ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/controllers/dry_admin/resources_controller.rb', line 7 def index # CONDITIONALLY SELECT ONLY RECORDS FROM 1:N RELATION where = {} @belongs_to = @model.reflect_on_all_associations(:belongs_to).map(&:name) @belongs_to.each do |association| association_column = (association.to_s+"_id").to_sym where[association_column] = params[association_column] if params[association_column].present? end @records = @model.where(where).paginate(:page => params[:page], :per_page => 15) @submodels = @model.reflect_on_all_associations(:has_many) end |
#new ⇒ Object
19 20 21 |
# File 'app/controllers/dry_admin/resources_controller.rb', line 19 def new @record = @model.new end |
#show ⇒ Object
32 33 34 |
# File 'app/controllers/dry_admin/resources_controller.rb', line 32 def show @record = @model.find(params[:id]) end |
#update ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'app/controllers/dry_admin/resources_controller.rb', line 40 def update @record = @model.find(params[:id]) if @record.update(resource_params) redirect_to({action: 'index'}, notice: "#{@model.name} successfully updated") else render 'edit' end end |