Module: Adminpanel::RestActions
- Extended by:
- ActiveSupport::Concern
- Included in:
- ApplicationController
- Defined in:
- app/controllers/concerns/adminpanel/rest_actions.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/concerns/adminpanel/rest_actions.rb', line 43 def create merge_params @resource_instance = @model.new(send(whitelisted_params)) respond_to do |format| if @resource_instance.save format.html { redirect_to @resource_instance } format.js do # if format js, request is from another controller's form if params[:belongs_request] # we are in other controller as a belongs_to, add option to select render 'adminpanel/templates/option_for_select' else # we are in other controller as a has_many, add checkbox render 'adminpanel/templates/checkbox' end end else format.html do render 'adminpanel/templates/new' end format.js do render 'adminpanel/templates/new' end end end end |
#destroy ⇒ Object
83 84 85 86 87 88 89 |
# File 'app/controllers/concerns/adminpanel/rest_actions.rb', line 83 def destroy @resource_instance.destroy respond_to do |format| format.html { redirect_to action: :index } format.js { render('adminpanel/templates/destroy') } end end |
#edit ⇒ Object
71 72 73 |
# File 'app/controllers/concerns/adminpanel/rest_actions.rb', line 71 def edit render 'adminpanel/templates/edit' end |
#index ⇒ Object
19 20 21 22 23 |
# File 'app/controllers/concerns/adminpanel/rest_actions.rb', line 19 def index if stale?(etag: @collection, public: true, template: false) render 'adminpanel/templates/index' end end |
#new ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/concerns/adminpanel/rest_actions.rb', line 31 def new @resource_instance = @model.new respond_to do |format| format.html do render 'adminpanel/templates/new' end format.js do render 'adminpanel/templates/new' end end end |
#show ⇒ Object
25 26 27 28 29 |
# File 'app/controllers/concerns/adminpanel/rest_actions.rb', line 25 def show if stale?(etag: @resource_instance, public: true, template: false) render 'adminpanel/templates/show' end end |
#update ⇒ Object
75 76 77 78 79 80 81 |
# File 'app/controllers/concerns/adminpanel/rest_actions.rb', line 75 def update if @resource_instance.update(send(whitelisted_params)) redirect_to @resource_instance else render 'adminpanel/templates/edit' end end |