当我的用户注册时,它最初会被重定向到其空白个人资料页面。
但是,我需要将用户重定向到其他信息页面以便检索更多信息
我的用户控制器看起来像这样
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
end
def new
@user = User.new
end
def additional_info
@user = User.new
end
def create
@user = User.new(user_params)
if @user.save
UserMailer.welcome_email(@user).deliver
sign_in @user
redirect_to users: 'additional_info'
flash[:success] = "Welcome to InYourShoes!"
return @user
else
render'new'
end
结束
private
def user_params
params.require(:user).permit(:name, :email, :password, :password_confirmation)
end
端
如您所见,additional_info是我正在尝试重定向到的另一个页面。我知道我创建了2个用户对象,但我不确定它是否正确。坦率地说,我有点失落。
我的网页路线是:
resources :users
resources :sessions, only: [:new, :create, :destroy]
match '/additionalinfo',to: 'users#additional_info', via: 'get'
感谢您的帮助!
答案 0 :(得分:2)
在你的路线
match '/additionalinfo',to: 'users#additional_info', via: 'get', as: :additional_info
控制器中的
redirect_to additional_info_path
答案 1 :(得分:0)
或者,您可以将重定向行更改为:
redirect_to action: 'additional_info'
假设您已在路线中定义了操作:
get :additional_info, to: 'users#additional_info' # use get rather than match