module Resources::RestActions
Public Instance Methods
create()
click to toggle source
# File lib/resources/rest_actions.rb, line 28 def create save_resource end
destroy()
click to toggle source
# File lib/resources/rest_actions.rb, line 43 def destroy destroy_resource end
edit()
click to toggle source
# File lib/resources/rest_actions.rb, line 32 def edit end
index()
click to toggle source
# File lib/resources/rest_actions.rb, line 20 def index end
new()
click to toggle source
# File lib/resources/rest_actions.rb, line 24 def new end
show()
click to toggle source
# File lib/resources/rest_actions.rb, line 36 def show end
update()
click to toggle source
# File lib/resources/rest_actions.rb, line 39 def update save_resource end
Protected Instance Methods
destroy_resource(&block)
click to toggle source
# File lib/resources/rest_actions.rb, line 84 def destroy_resource &block @destroy_resource = resource.destroy after_redirect_for = "after_#{action_name}_path_for" if block_given? block.call(@destroy_resource) else if self.class.resource_configuration.flash && request.format.html? if self.class.resource_configuration.flash.respond_to?(:call) flash[:notice] = self.class.resource_configuration.flash.call(resource, params, self) else flash[:notice] = I18n.t("resources.#{controller_path}.#{action_name}") end end if self.respond_to?(after_redirect_for, true) respond_with resource, location: send(after_redirect_for), action: :destroy else respond_with resource, location: url_for(controller: params[:controller], action: :index), action: :destroy end end end
resource_saved?()
click to toggle source
# File lib/resources/rest_actions.rb, line 49 def resource_saved? @resource_saved end
save_resource(&block)
click to toggle source
# File lib/resources/rest_actions.rb, line 53 def save_resource &block resource.assign_attributes(resource_manager.params_resource) @resource_saved = resource.save after_redirect_for = "after_#{action_name}_path_for" action_path_for = case action_name when "create" :new when "update" :edit else :index end if block_given? block.call(resource) else if self.class.resource_configuration.flash && request.format.html? && resource_saved? if self.class.resource_configuration.flash.respond_to?(:call) flash[:notice] = self.class.resource_configuration.flash.call(resource, params, self) else flash[:notice] = I18n.t("resources.#{controller_path}.#{action_name}") end end if self.respond_to?(after_redirect_for, true) respond_with resource, location: send(after_redirect_for) else respond_with resource, location: url_for(controller: params[:controller], action: :index), action: action_path_for end end end