Module: Stepper::ControllerAdditions::ClassMethods

Defined in:
lib/stepper/controllers/controller_additions.rb

Instance Method Summary collapse

Instance Method Details

#has_steps(*args) ⇒ Object

Sets up create, update, new actions for controller and before filter for load resource. If you use cancan or load resource in other way it will get loaded resource.

First parameters can be name of resource, for example:

class CompaniesController < ApplicationController
  has_steps :my_company
end

It will load or build resource in @my_company variable

First argument it isn’t required:

class CompaniesController < ApplicationController
  has_steps
end

In this case resource will be loaded or built into @company variable

You can setup redirection for each save, previous_step, next_step and finish step to other action than default, options should have after prefix:

class CompaniesController < ApplicationController
  has_steps :redirect_to => { :after_save => {:action => :new} }
end

You can set proc that will be executed for current controller:

class CompaniesController < ApplicationController
  has_steps :redirect_to => { :after_finish => proc{|controller, resource| controller.show_companies_url(resource)} }
end


38
39
40
41
# File 'lib/stepper/controllers/controller_additions.rb', line 38

def has_steps(*args)
  include InstanceMethods
  stepper_resource_class.add_before_filter(self, *args)
end

#stepper_resource_classObject



43
44
45
# File 'lib/stepper/controllers/controller_additions.rb', line 43

def stepper_resource_class
  ControllerResource
end