在Devise和Rails中创建仅限电子邮件注册时遇到问题

时间:2013-01-11 21:36:30

标签: ruby-on-rails authentication devise

我目前正在设置基于tutorial on Devise labeled Email only signup的项目,并且似乎遇到了一个我无法解决的特定错误。我有插件可以执行除步骤3之外的所有操作,因为它无法找到我添加的名为confirm的自定义方法。我已经告诉Devise使用

devise_for :users, :controllers => {:confirmations => 'confirmations'}

我的用户插件,但它忽略了我的控制器。

我有一个名为confirmations_controller.rb的控制器,它包含以下代码:

class ConfirmationsController < Devise::ConfirmationsController
  def show
    self.resource = resource_class.find_by_confirmation_token(params[:confirmation_token])
    super if resource.confirmed? 
  end

  def confirm
    self.resource = resource_class.find_by_confirmation_token(params[resource_name][:confirmation_token])
    if resource.update_attributes(params[resource_name].except(:confirmation_token)) && resource.password_match?
      self.resource = resource_class.confirm_by_token(params[resource_name][:confirmation_token])
      set_flash_message :notice, :confirmed
      sign_in_and_redirect(resource_name, resource)
    else
      render :action => "show"
  end
end

确切的错误是:

undefined method `confirmed?' for #<User:0x425f130>

我正在使用rails版本3.2.9并设计版本2.2.1

我正在学习rails和ruby,所以我真的希望有人可以帮助我。

1 个答案:

答案 0 :(得分:2)

错误消息是关于未定义的confirmed?方法。您添加的自定义方法为confirm

confirmable module of device

添加了confirmed?方法

正如Jesse在上面的评论中提到的,为User类启用'确认'模块。

示例用户类:

class User < ActiveRecord::Base
  devise ..., :confirmable, ...

  ...

end