2
votes

So, I'd like to make my applications sign-up process two steps (and eventually more in the future). However, I'm having trouble getting Wicked working with Devise.. Specifically, I'm un-sure of how to implement the correct controller code, given Devise's controller is pre-built.

How it should work is, the user fills out their standard account info, (email, username, pass, password confirmation) and then clicks Next, and on the second page they fill out their age.

This is what I have so far:

RegistrationController.rb (Devise controller)

class RegistrationsController < Devise::RegistrationsController
  def new
    super
  end

  def create
    super
  end

  protected

  def users_steps_path(resource)
    '/user_steps'
  end
 end 

UserStepsController.rb (Wicked Controller)

class UserStepsController < ApplicationController
  include Wicked::Wizard
  steps :add_age

  def show
    render_wizard
  end

  def update
    render_wizard
  end
end 

First step, devise/registrations/new.html.erb

<div class="styled email-input2">
  <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
  <%= devise_error_messages! %>
    <div><%= f.email_field :email, autofocus: true, placeholder: "Email", class: "email-input" %></div>
    <div><%= f.text_field :username, autofocus: true, placeholder: "Username", class: "email-input" %></div>
    <div><%= f.password_field :password, autocomplete: "off", placeholder: "Password", class: "email-input" %></div>
    <div><%= f.password_field :password_confirmation, autocomplete: "off", placeholder: "Password confirmation", class: "email-input" %></div>
</div>
    <div class="get_motivated2">
  <%= f.submit "Sign up", class: "sign-up btn-danger" %>
<% end %>
</div>
</div> 

Second step, add_age.html.erb

<%= form_for @user, url: wizard_path do |f| %>
  <%= f.age :age %>
  <%= f.submit "Add Age" %>
<% end %> 

Routes.rb

  resources :user_steps

Happy to provide any additional code if necessary to get this working!

1

1 Answers

2
votes

Just ensure first after sign up you are redirecting to wicked's first step url.

class RegistrationsController < Devise::RegistrationsController
  protected

  def after_sign_up_path_for(resource)
    'your_wicked_first_step_path'
  end
end

To registrar this controller:

devise_for :users, :controllers => { :registrations => "registrations" }

references: https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-up-%28registration%29