Using Wicked with Devise for a sign up wizard

Posted by demondeac11 on Stack Overflow See other posts from Stack Overflow or by demondeac11
Published on 2012-06-01T02:33:17Z Indexed on 2012/06/02 4:40 UTC
Read the original article Hit count: 846

I am using devise with wicked to create a sign up wizard, but I am unsure about a problem I am having creating profiles. After a user provides their email & password they are forwarded to a step to create a profile based on whether they have specified they are a shipper or carrier. However I am unsure what the code should be in the controller and the forms to generically create a profile. Here is the code I have for the application:

The steps controller:

class UserStepsController < ApplicationController
  include Wicked::Wizard
  steps :carrier_profile, :shipper_profile


 def create
   @user = User.last
   case step
   when :carrier_profile
     @profile = CarrierProfile.create!(:dot => params[:dot])
     if @profile.save
        render_wizard @user
     else
        flash[:alert] = "Record not saved"
     end
   when :shipper_profile
     @profile = ShipperProfile.create!(params[:shipper_profile)
     if @profile.save
        render_wizard @user
     else
        flash[:alert] = "Record not saved"
     end
   end
 end

end end

  def show
    @user = User.last
    @carrier_profile = CarrierProfile.new
    @shipper_profile = ShipperProfile.new
    case step
    when :carrier_profile
      skip_step if @user.shipper?
    when :shipper_profile
      skip_step if @user.carrier?
    end
    render_wizard
  end
end

The form for a carrier profile:

<% form_for @carrier_profile , url: wizard_path, method: :post do |f| %>
  <div>
    <%= f.label :dot, "Please enter your DOT Number:" %>
    <%= f.text_field :dot %>
  </div>

  <%= f.submit "Next Step", class: "btn btn-primary" %>
<% end %>

The form for a shipper profile:

<% form_for @shipper_profile , url: wizard_path, method: :post do |f| %>
  <div>
    <%= f.label :company_name, "What is your company name?" %>
    <%= f.text_field :company_name %>
  </div>

  <%= f.submit "Next Step", class: "btn btn-primary" %>
<% end %>

The user model:

class User < ActiveRecord::Base
  has_one :carrier_profile
  has_one :shipper_profile
end

How would I be able to write a generic new and create method to handle creating both profiles? With the current code it is stating that the user_steps controller has no POST method, although if I run rake routes I find that this is untrue.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby-on-rails-3