module Undercarriage::Controllers::Restful::Actions::UpdateConcern
Update restful action
Usage
class ExamplesController < ApplicationController include Undercarriage::Controllers::RestfulConcern end
Public Instance Methods
update()
click to toggle source
Update action
Usage
class ExamplesController < ApplicationController include Undercarriage::Controllers::RestfulConcern ## # This method is only needed if you want to override the action entirely. Otherwise, it is not needed. # Database resources can be accessed as `@update_resource` or `@example` # # def update # ... # end end
# File lib/undercarriage/controllers/restful/actions/update_concern.rb, line 41 def update nested_resource_pre_build respond_to do |format| if @update_resource.update(update_resource_params) after_update_action format.html do flash[flash_status_type] = flash_updated_message redirect_to location_after_update end format.json { render :show, status: :ok, location: location_after_update } else nested_resource_build format.html { render :edit } format.json { render json: @update_resource.errors, status: :unprocessable_entity } end end end
Protected Instance Methods
update_resource_content()
click to toggle source
Update restful action
Usage
class ExamplesController < ApplicationController include Undercarriage::Controllers::RestfulConcern ## # This method is only needed if you want to override the query entirely. Otherwise, it is not needed. # Database resources can be accessed as `@example` # # def update_resource_content # ... # end ## # To add authorization through something like Pundit, the following could be used # # def update_resource_content # super # # authorize @example # end ## # The `resource_content` method can also be overwritten. Be careful with this because the `show`, # `edit` and `destroy` actions will also use this method # # def resource_content # ... # end end
# File lib/undercarriage/controllers/restful/actions/update_concern.rb, line 98 def update_resource_content resource_content end
Private Instance Methods
update_resource()
click to toggle source
# File lib/undercarriage/controllers/restful/actions/update_concern.rb, line 104 def update_resource @update_resource ||= update_resource_content end