所以,我想让我的应用程序注册过程分两步(最终将来更多)。但是,我无法让Wicked与Devise.合作。具体来说,我不确定如何实现正确的控制器代码,因为Devise的控制器是预先构建的。
它应该如何工作,用户填写他们的标准帐户信息(电子邮件,用户名,通行证,密码确认),然后单击“下一步”,在第二页上填写他们的年龄。
这是我到目前为止所做的:
RegistrationController.rb(设计控制器)
class RegistrationsController < Devise::RegistrationsController
def new
super
end
def create
super
end
protected
def users_steps_path(resource)
'/user_steps'
end
end
UserStepsController.rb(邪恶控制器)
class UserStepsController < ApplicationController
include Wicked::Wizard
steps :add_age
def show
render_wizard
end
def update
render_wizard
end
end
第一步,设计/注册/ 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>
第二步,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
如果有必要,请尽快提供任何其他代码以使其正常运行!
答案 0 :(得分:2)
注册后首先确保您重定向到邪恶的第一步网址。
class RegistrationsController < Devise::RegistrationsController
protected
def after_sign_up_path_for(resource)
'your_wicked_first_step_path'
end
end
注册此控制器:
devise_for :users, :controllers => { :registrations => "registrations" }