Module: Stepper::ActiveRecordAdditions::ClassMethods
- Defined in:
- lib/stepper/models/active_record_additions.rb
Instance Method Summary collapse
-
#has_steps(options = {}) ⇒ Object
Sets up methods and define steps.
Instance Method Details
#has_steps(options = {}) ⇒ Object
Sets up methods and define steps. For example, you have model Company
and you want to fill it fields in few steps description, kind and address:
class Company < ActiveRecord::Base
has_steps :steps => %w{ description kind address }
end
Model should have current step column, by default it name is current_step
. It should be added by migration:
add_column :companies, :current_step, :string
add_index :companies, :current_step
The column name can be set up with option current_step_column
.
Options:
- :
steps
-
It is required option. Define steps for multistep form.
- :
current_step_column
-
Define what field use for save current step of form. Default
current_step
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/stepper/models/active_record_additions.rb', line 32 def has_steps( = {}) #check options raise Stepper::StepperException.new("Options for has_steps must be in a hash.") unless .is_a? Hash .each do |key, value| unless [:current_step_column, :steps].include? key raise Stepper::StepperException.new("Unknown option for has_steps: #{key.inspect} => #{value.inspect}.") end end raise Stepper::StepperException.new(":steps condition can't be blank") if [:steps].blank? #set current step column class_attribute :stepper_current_step_column, :instance_writer => false self.stepper_current_step_column = [:current_step_column] || :current_step class_attribute :stepper_options, :instance_writer => false self. = self.validate :current_step_validation include InstanceMethods end |