我在rails(3.2.12)应用程序中使用devise(2.2.3)。
我有2个设计模型,设计管理员和用户 在设计模型Admin authentication_keys使用电子邮件和User authentication_keys使用用户名(但仍然有电子邮件),管理模型完全正常,但忘记密码功能的用户模型已决定停止工作。当我输入电子邮件地址并单击“发送给我重置说明”时,我收到的错误消息如下:
NoMethodError in PasswordusersController#create
undefined method `slice' for nil:NilClass
passwordadmins_controller.rb
与passwordusers_controller.rb
之间没有显着差异,唯一的区别是名为
我需要做些什么来解决这个问题?
这passwordusers_controller.rb
class PasswordusersController < Devise::PasswordsController
prepend_before_filter :require_no_authentication
append_before_filter :assert_reset_token_passed, :only => :edit
def new
super
end
def create
self.resource = resource_class.send_reset_password_instructions(resource_params)
if successfully_sent?(resource)
redirect_to new_session_user_path, :notice => "Instruction Send To Your Email"
else
respond_with(resource)
end
end
def edit
super
end
def update
self.resource = resource_class.reset_password_by_token(resource_params)
if resource.errors.empty?
resource.unlock_access! if unlockable?(resource)
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
set_flash_message(:notice, flash_message) if is_navigational_format?
sign_in(resource_name, resource)
redirect_to home_subdomain_path, :notice => "Password changed"
else
respond_with resource
end
end
protected
def after_sending_reset_password_instructions_path_for(resource_name)
new_session_user_path
end
def assert_reset_token_passed
if params[:reset_password_token].blank?
set_flash_message(:error, :no_token)
redirect_to new_session_user_path
end
end
def unlockable?(resource)
resource.respond_to?(:unlock_access!) &&
resource.respond_to?(:unlock_strategy_enabled?) &&
resource.unlock_strategy_enabled?(:email)
end
end
更新
<%= form_for("User", :url => passwordusers_create_path(resource_name), :html => { :method => :post }) do |f| %>
<%= render 'layouts/flash_messages' %>
<div class="row-fluid">
<div class="input-prepend">
<span class="add-on"><i class="icon-envelope"></i></span>
<%= f.email_field :email, 'style' => 'width:240px;', :placeholder => 'Email' %>
</div>
<div class="dr"><span></span></div>
<%= f.submit "Send", :class => 'btn btn-block btn-primary' %>
<div class="dr"><span></span></div>
</div>
<% end %>
感谢您的帮助
答案 0 :(得分:1)
资源设计默认使用小写,试试这个,
form_for("User" .....
更改为
form_for("user"