Class: Resourceize::ResourcesController

Inherits:
ActionController::Base
  • Object
show all
Includes:
Before, InstanceVariables, RoutingMethods
Defined in:
lib/resourceize/resources_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RoutingMethods

included

Methods included from InstanceVariables

included, object_meta

Methods included from Before

included

Class Method Details

.follow(action, &block) ⇒ Object



32
33
34
35
36
# File 'lib/resourceize/resources_controller.rb', line 32

def self.follow(action, &block)
  action = :"#{action}"
  @follow ||= {}
  @follow[action] = block
end

.set_resource(resource_class) ⇒ Object



28
29
30
# File 'lib/resourceize/resources_controller.rb', line 28

def self.set_resource(resource_class)
  request.instance_eval {@resource = resource_class}
end

Instance Method Details

#createObject



54
55
56
57
58
59
60
# File 'lib/resourceize/resources_controller.rb', line 54

def create
  if @object.save
      success :redirect_to => follow_action(:create) || (can_render_show? ? object_path(@object) : collection_path)
  else
      failure :render => template_for("new")
  end
end

#destroyObject



72
73
74
75
76
77
78
# File 'lib/resourceize/resources_controller.rb', line 72

def destroy
  if @object.destroy
    success :redirect_to => follow_action(:destroy) || collection_path
  else
    failure :redirect_to => collection_path
  end
end

#editObject



44
45
46
# File 'lib/resourceize/resources_controller.rb', line 44

def edit
  render :template => template_for("edit")
end

#indexObject



49
50
51
# File 'lib/resourceize/resources_controller.rb', line 49

def index
  render :template => template_for("index")
end

#newObject



39
40
41
# File 'lib/resourceize/resources_controller.rb', line 39

def new
  render :template => template_for("new")
end

#showObject



81
82
83
# File 'lib/resourceize/resources_controller.rb', line 81

def show

end

#updateObject



63
64
65
66
67
68
69
# File 'lib/resourceize/resources_controller.rb', line 63

def update
  if @object.update_attributes(params[:"#{request.resource_name}"])
      success :redirect_to  => follow_action(:update) || (can_render_show? ? object_path(@object) : collection_path)
  else
      failure :render => template_for("edit")
  end
end