Module: Wicked::Controller::Concerns::RenderRedirect

Extended by:
ActiveSupport::Concern
Included in:
Wizard
Defined in:
lib/wicked/controller/concerns/render_redirect.rb

Instance Method Summary collapse

Instance Method Details

#finish_wizard_path(params = {}) ⇒ Object

TODO redirect to resource if one is passed to render_wizard



49
50
51
52
53
# File 'lib/wicked/controller/concerns/render_redirect.rb', line 49

def finish_wizard_path(params = {})
  url = '/'
  url = "#{url}?#{params.to_query}" unless params.blank?
  url
end

#process_resource!(resource, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/wicked/controller/concerns/render_redirect.rb', line 16

def process_resource!(resource, options = {})
  return unless resource

  if options[:context] && resource.method(:save).arity >= 1
    did_save = resource.save(context: options[:context])
  else
    did_save = resource.save
  end

  if did_save
    @skip_to ||= @next_step
  else
    @skip_to = nil
  end
end

#redirect_to_finish_wizard(options = {}, params = {}) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/wicked/controller/concerns/render_redirect.rb', line 55

def redirect_to_finish_wizard(options = {}, params = {})
  wicked_final_redirect_path = method(:finish_wizard_path).arity == 1 ? finish_wizard_path(params) : finish_wizard_path
  Rails.logger.debug("Wizard has finished, redirecting to finish_wizard_path: #{wicked_final_redirect_path.inspect}")
  # flash.keep is required for Rails 3 where a flash message is lost on a second redirect.
  flash.keep
  redirect_to wicked_final_redirect_path, options
end

#redirect_to_next(next_step, options = {}, params = {}) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/wicked/controller/concerns/render_redirect.rb', line 40

def redirect_to_next(next_step, options = {}, params = {})
  if next_step.nil?
    redirect_to_finish_wizard(options, params)
  else
    redirect_to wizard_path(next_step, params), options
  end
end

#render_step(the_step, options = {}, params = {}) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/wicked/controller/concerns/render_redirect.rb', line 32

def render_step(the_step, options = {}, params = {})
  if the_step.nil? || the_step.to_s == Wicked::FINISH_STEP
    redirect_to_finish_wizard options, params
  else
    render the_step, options
  end
end

#render_wizard(resource = nil, options = {}, params = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/wicked/controller/concerns/render_redirect.rb', line 5

def render_wizard(resource = nil, options = {}, params = {})
  process_resource!(resource, options)

  if @skip_to
    url_params = (@wicked_redirect_params || {}).merge(params)
    redirect_to wizard_path(@skip_to, url_params), options
  else
    render_step(wizard_value(step), options, params)
  end
end