使用 Wicked Gem 和 Devise 在 rails 中使用多种形式
Multi-form in rails using Wicked Gem and Devise
我正在尝试使用 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
1.Neededcontroller中的update方法,需要在show方法中定义user:
def show
@user = current_user
render_wizard
end
def update
@user = current_user
@user.update_attributes(user_params)
render_wizard @user
end
2.Needed 生成设计控制器:
rails generate devise:controllers [scope]
3.Update 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.This控制器无效,需要使用设计生成的控制器:
class UsersController < Devise::RegistrationsController
我正在尝试使用 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
1.Neededcontroller中的update方法,需要在show方法中定义user:
def show
@user = current_user
render_wizard
end
def update
@user = current_user
@user.update_attributes(user_params)
render_wizard @user
end
2.Needed 生成设计控制器:
rails generate devise:controllers [scope]
3.Update 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.This控制器无效,需要使用设计生成的控制器:
class UsersController < Devise::RegistrationsController