我在 rails (3.2.12) 应用程序中使用设计 (2.2.3)。
我有 2 个设计模型,设计 Admin 和 User 在设计模型 Admin authentication_keys 使用电子邮件和 User authentication_keys 使用用户名(但仍然有电子邮件),管理模型完全正常工作,但忘记密码功能的用户模型已决定停止工作。当我输入电子邮件地址并单击“向我发送重置说明”时,我收到如下错误消息:
NoMethodError in PasswordusersController#create
undefined method `slice' for nil:NilClass
passwordadmins_controller.rb
with之间没有显着差异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 %>
谢谢你的帮助