Joh*_*ohn 3 ruby-on-rails devise ruby-on-rails-3.1
将此行添加到devise/registrations/new.html.haml文件(视图)后:
%div
= f.label :account_type
%br/
= f.select(:account_type, [["Usertype1","usertype1"],["Usertype2","usertype2"]], {:selected => nil, :prompt => 'Pick One'})
Run Code Online (Sandbox Code Playgroud)
单击确认电子邮件中的确认链接后出现以下错误:
ActionController::ActionControllerError in Devise::ConfirmationsController#show
Cannot redirect to nil!
Run Code Online (Sandbox Code Playgroud)
只有在我注册时选择Usertype2才会发生这种情况.我还将account_type设为attr_accessible.account_type似乎已分配(我在rails控制台中检查过),开发日志没有任何进一步的信息.
我认为这是发生错误的设备确认控制器中的行:
respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
Run Code Online (Sandbox Code Playgroud)
此外,该帐户正在确认,但在尝试登录时,我得到以下内容:
undefined method `user_url' for #<Devise::SessionsController:0x9d1659c>
Run Code Online (Sandbox Code Playgroud)
这是在设计会话控制器的创建操作中.
任何帮助,将不胜感激.谢谢!
约翰
您提到的两个错误是同一个,主要是当您成功登录时,Devise无法检测到您重定向的位置.当您有多个模型或尝试在路径文件中设置自定义重定向(登录后)时,通常会发生此问题.
尝试在ApplicationController中定义路径.
设计文档说,after_sign_in_path_for方法采用实际的模型对象(即:正在登录的模型)
def after_sign_in_path_for(resource)
signed_in_path_for_user
end
Run Code Online (Sandbox Code Playgroud)
注意:您可以对多个Devise路径/变量执行相同操作(覆盖它们).另外,有关在同一个应用程序中为多个Devise模型执行此操作的更多信息,您可以查看此问题并获得答案.