New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redirect_to_finish_wizard #54

Closed
FranzFerd opened this Issue Jan 29, 2013 · 6 comments

Comments

Projects
None yet
4 participants
@FranzFerd

FranzFerd commented Jan 29, 2013

Hey, great gem and it works great for me, too.

I do not want to redirect to root_url and thus would like to use the
def redirect_to_finish_wizard. I copied it from the example but unfortunately it throws me an error:

wrong number of arguments (1 for 0)
app/controllers/event_steps_controller.rb:18:in redirect_to_finish_wizard' app/controllers/event_steps_controller.rb:7:inshow'
{"id"=>"finish"}

I am pretty sure it has nothing to do with the gem but for the moment I am really stuck. So, thx for any help.

@schneems

This comment has been minimized.

Owner

schneems commented Jan 29, 2013

can you gist me the controller that you're including wicked in? or at least the part where you are using redirect_to_finish_wizard ?

@FranzFerd

This comment has been minimized.

FranzFerd commented Jan 29, 2013

Hey, of course.
I use a pretty standard event_steps_controller:

class EventStepsController < ApplicationController
  include Wicked::Wizard
  steps :personal, :social, :sponsorship

  def show
    @event = current_event
    render_wizard
  end

  def update
    @event = current_event

    @event.attributes = params[:event]
    render_wizard @event
  end

private
  def redirect_to_finish_wizard
    redirect_to root_path , notice: "Thank you for signing up."
  end
end

The event_controller is as follows:

def create
  @event = Event.new(params[:event])
  @event.user_id = current_user.id
  if @event.save
    session[:event_id] = @event.id
    redirect_to event_steps_path
  else
    render :new
  end
end

Could it be a routing error? I am not that advanced in rails..
Thx a lot!

@schneems

This comment has been minimized.

Owner

schneems commented Jan 29, 2013

I fixed your indentation and style there, you can use three back ticks

```

before and after code blocks to make them more readable in github.

You're supposed to customize the final destination using finish_wizard_path which returns a url

def finish_wizard_path
  user_path(current_user)
end

I didn't intend or really even think of people over-writing redirect_to_finish_wizard, it's not what I would consider in the public interface. Here is the current method definition in Wicked 0.5.0

  def redirect_to_finish_wizard(options = nil)
    redirect_to finish_wizard_path, options
  end

It is written taking in a hash of options. Since my internal code is calling that method with an argument, your method also has to have an argument, so you'll need to change it from

  def redirect_to_finish_wizard
    redirect_to root_path , notice: "Thank you for signing up."
  end

To:

  def redirect_to_finish_wizard(options = nil)
    redirect_to root_path , notice: "Thank you for signing up."
  end
@FranzFerd

This comment has been minimized.

FranzFerd commented Jan 29, 2013

Hi!
Thanks a lot! It works perfectly fine.
Great gem!

@FranzFerd FranzFerd closed this Jan 30, 2013

@mahtab732

This comment has been minimized.

mahtab732 commented May 13, 2017

Thank you schneems

@fkotsian

This comment has been minimized.

fkotsian commented May 14, 2017

Seconded the thanks! Useful explanation above. FYI, the redirect_to_finish_wizard suggestion comes from Ryan Bates's RailsCast on Wicked: http://railscasts.com/episodes/346-wizard-forms-with-wicked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment