module Resourceful::Default::Actions

Contains the definitions of the default resourceful actions. These are made available with the Builder#actions method.

These methods are very compact, so the best way to understand them is just to look at their source. Check out Resourceful::Accessors and Resourceful::Callbacks for the documentation of the methods called within the actions.

Along with each action is listed the RESTful method which corresponds to the action. The controller in the examples is FoosController, and the id for single-object actions is 12.

Public Instance Methods

create() click to toggle source

POST /foos

# File lib/resourceful/default/actions.rb, line 34
def create
  build_object
  load_object
  before :create
  if current_object.save
    save_succeeded!
    after :create
    response_for :create
  else
    save_failed!
    after :create_fails
    response_for :create_fails
  end
end
destroy() click to toggle source

DELETE /foos/12

# File lib/resourceful/default/actions.rb, line 88
def destroy
  #load_object
  before :destroy
  if current_object.destroy
    after :destroy
    head :ok
  else
    after :destroy_fails
    response_for :destroy_fails
  end
end
edit() click to toggle source

GET /foos/12/edit

# File lib/resourceful/default/actions.rb, line 81
def edit
  #load_object
  before :edit
  response_for :edit
end
index() click to toggle source

GET /foos

# File lib/resourceful/default/actions.rb, line 17
def index
  #load_objects
  before :index
  response_for :index
end
new() click to toggle source

GET /foos/new

# File lib/resourceful/default/actions.rb, line 73
def new
  build_object
  load_object
  before :new
  response_for :new
end
show() click to toggle source

GET /foos/12

# File lib/resourceful/default/actions.rb, line 24
def show
  # NOTE - Moved this call to a more generic place
  #load_object
  before :show
  response_for :show
rescue
  response_for :show_fails
end
update() click to toggle source

PUT /foos/12

# File lib/resourceful/default/actions.rb, line 50
def update
  #load_object
  before :update

  begin
    result = current_object.update_attributes object_parameters
  rescue ActiveRecord::StaleObjectError
    current_object.reload
    result = false
  end

  if result
    save_succeeded!
    after :update
    response_for :update
  else
    save_failed!
    after :update_fails
    response_for :update_fails
  end
end