Skip to content

Commit

Permalink
Fix issue with not being able to set a validation context
Browse files Browse the repository at this point in the history
  • Loading branch information
sirwolfgang committed Jul 24, 2018
1 parent 409f75c commit 779cd68
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,20 @@ previous_wizard_path # Url of the previous step
**Controller Tidbits:**

```ruby
steps :first, :second # Sets the order of steps
step # Gets current step
next_step # Gets next step
previous_step # Gets previous step
skip_step # Tells render_wizard to skip to the next logical step
jump_to(:specific_step) # Jump to :specific_step
render_wizard # Renders the current step
render_wizard(@user) # Shows next_step if @user.save, otherwise renders
wizard_steps # Gets ordered list of steps
past_step?(step) # does step come before the current request's step in wizard_steps
future_step?(step) # does step come after the current request's step in wizard_steps
previous_step?(step) # is step immediately before the current request's step
next_step?(step) # is step immediately after the current request's step
steps :first, :second # Sets the order of steps
step # Gets current step
next_step # Gets next step
previous_step # Gets previous step
skip_step # Tells render_wizard to skip to the next logical step
jump_to(:specific_step) # Jump to :specific_step
render_wizard # Renders the current step
render_wizard(@user) # Shows next_step if @user.save, otherwise renders
render_wizard(@user, context: :account_setup) # Shows next_step if @user.save(context: :account_setup), otherwise renders
wizard_steps # Gets ordered list of steps
past_step?(step) # does step come before the current request's step in wizard_steps
future_step?(step) # does step come after the current request's step in wizard_steps
previous_step?(step) # is step immediately before the current request's step
next_step?(step) # is step immediately after the current request's step
```

**Redirect options**
Expand Down
23 changes: 14 additions & 9 deletions lib/wicked/controller/concerns/render_redirect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Wicked::Controller::Concerns::RenderRedirect


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

if @skip_to
url_params = (@wicked_redirect_params || {}).merge(params)
Expand All @@ -13,13 +13,19 @@ def render_wizard(resource = nil, options = {}, params = {})
end
end

def process_resource!(resource)
if resource
if resource.save
@skip_to ||= @next_step
else
@skip_to = nil
end
def process_resource!(resource, options = {})
return unless resource

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

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

Expand Down Expand Up @@ -54,4 +60,3 @@ def redirect_to_finish_wizard(options = {}, params = {})
redirect_to wicked_final_redirect_path, options
end
end

0 comments on commit 779cd68

Please sign in to comment.