我正在使用Rails 3.2.13
,Devise 3.2.4
。用户注册后,确认链接生成。设计 - 用户确认后如何重定向到其他页面
localhost:3000/users/confirmation?confirmation_token=HpPHitLtV3CnLy2z1ZmQ
我想在点击确认链接后重定向到导师/新动作。
但确认后重定向到/用户/ sign_in我不想要的。以下是我迄今为止所做的代码。
路线
devise_for :users
devise_for :users, :controllers => { :confirmations => 'confirmations' }
创建确认书控制器和覆盖从设计:: ConfirmationsController
class ConfirmationsController < Devise::ConfirmationsController
protected
def after_confirmation_path_for(resource_name, resource)
if resource.has_role? :user
redirect_to new_mentor_path("account_id")
else
root_path
end
end
end
在ConfirmationsController,可能是我必须添加一些额外的代码。请提供一些解决方案。
在应用控制器我把下面的代码,这需要我的导师/学生家全成符号后在
def after_sign_in_path_for(resource_or_scope)
if resource_or_scope.is_a?(User)
if current_user.user_type == "mentor"
home_mentors_path(:account_id => current_user.account_id)
else
home_students_path(:account_id => current_user.account_id)
end
end
末
def after_sign_up_path_for(resource_or_scope)
root_path
end
一般的逻辑是这样的,但我没有得到如何与Devise做到这一点。
def activate
@user = User.where("activation_code = ?","#{params[:id]}").first
if [email protected]?
if @user.created_at < 24.hours.ago
if @user and @user.activate
cookies[:user_id][email protected]
if @user.user_type == "student"
redirect_to new_student_path
else
redirect_to new_mentor_path
end
else
@user.destroy
redirect_to "/"
end
else
@user.destroy
redirect_to "/"
end
else
redirect_to "/"
end
末
看起来像'sign_in'重定向意味着你没有登录确认后?你能确认你的新用户在确认后登录吗? –
您的问题有两个解决方案,有效相似,可以找到[这里] [1] [1]:http://stackoverflow.com/questions/10926626/devise-redirect-after-confirmation –
@RichPeck :是的用户确认,我也登录。我只是想确认后,没有登录,它应该去辅导员/新页面。 –