我正在尝试使用Wicked gem设置多表单登录系统。按照以下步骤操作时,我已正确安装并正确运行:http://railscasts.com/episodes/346-wizard-forms-with-wicked。
我没有被重定向到user_step_paths?一切都按照教程中的说明完成,但我猜是因为我正在使用设计我需要在设计继承的控制器中完成它吗?我的代码在下面是控制器:
users_controller.rb
class UsersController < Devise::RegistrationsController
def new
@user = User.new
end
def create
@user = User.new(params[:sign_up])
if @user.save
session[:user_id] = @user.id
redirect_to user_steps_path
else
redirect_to new_user_registration_path
end
end
end
users_steps_controller.rb
class UserStepsController < ApplicationController
include Wicked::Wizard
steps :education, :social
def show
render_wizard
end
end
路由
get 'pages/home'
devise_for :users, :controllers => { :registrations => 'users'}
resources :user
resources :user_steps
答案 0 :(得分:3)
1.需要控制器中的更新方法,并且需要在show方法中定义用户:
def show
@user = current_user
render_wizard
end
def update
@user = current_user
@user.update_attributes(user_params)
render_wizard @user
end
2.需要生成设计控制器:
rails generate devise:controllers [scope]
3.更新设备的registration_controller
class Users::RegistrationsController < Devise::RegistrationsController
# before_filter :configure_sign_up_params, only: [:create]
# before_filter :configure_account_update_params, only: [:update]
# GET /resource/sign_up
def new
super
end
# POST /resource
def create
super
end
# GET /resource/edit
# def edit
# super
# end
# PUT /resource
def update
super
end
# The path used after sign up.
def after_sign_up_path_for(resource)
user_steps_path
end
# The path used after sign up for inactive accounts.
def after_inactive_sign_up_path_for(resource)
super(resource)
end
end
4.此控制器无效,您需要通过设计使用生成的控制器:
class UsersController < Devise::RegistrationsController