Class: HyperAdmin::ResourceController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- HyperAdmin::ResourceController
- Defined in:
- app/controllers/hyper_admin/resource_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #resource ⇒ Object
- #resource_class ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/hyper_admin/resource_controller.rb', line 34 def create @resource = @resource_class.new params[@resource_class.model_name.param_key] if @resource.save render json: @resource else render json: @resource.errors, status: 422 end end |
#destroy ⇒ Object
54 55 56 57 58 59 60 |
# File 'app/controllers/hyper_admin/resource_controller.rb', line 54 def destroy @resource = @resource_class.find params[:id] @resource.destroy head 200 end |
#edit ⇒ Object
26 27 28 29 30 31 32 |
# File 'app/controllers/hyper_admin/resource_controller.rb', line 26 def edit @resource = resource @attributes = @resource.attributes.delete_if do |k, v| k.to_sym.in? [ :id, :created_at, :updated_at ] end render 'admin/resources/edit' end |
#index ⇒ Object
8 9 10 11 |
# File 'app/controllers/hyper_admin/resource_controller.rb', line 8 def index @resources = resource_class.all render 'admin/resources/index' end |
#new ⇒ Object
18 19 20 21 22 23 24 |
# File 'app/controllers/hyper_admin/resource_controller.rb', line 18 def new @resource = resource_class.new @attributes = @resource.attributes.delete_if do |k, v| k.to_sym.in? [ :id, :created_at, :updated_at ] end render 'admin/resources/new' end |
#resource ⇒ Object
62 63 64 |
# File 'app/controllers/hyper_admin/resource_controller.rb', line 62 def resource resource_class.find params[:id] end |
#resource_class ⇒ Object
66 67 68 |
# File 'app/controllers/hyper_admin/resource_controller.rb', line 66 def resource_class raise "This method must be overridden" end |
#show ⇒ Object
13 14 15 16 |
# File 'app/controllers/hyper_admin/resource_controller.rb', line 13 def show @resource = resource render 'admin/resources/show' end |
#update ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/hyper_admin/resource_controller.rb', line 44 def update @resource = @resource_class.find params[:id] if @resource.update params[@resource_class.model_name.param_key] render json: @resource else render json: @resource.errors, status: 422 end end |