使用Devise的Registrations控制器中的自定义方法

时间:2013-01-19 11:56:12

标签: ruby-on-rails devise

我有一个明确的用户,我希望能够让他确认他的帐户重新输入他的电子邮件和姓名(因为这些已被第三方填写)。所以这就是我所拥有的:

def confirm_account
    if request.get?
      self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
    elsif request.put?
      self.resource = build_resource(resource_params)
      if self.resource.save 
      else
        respond_with resource
      end
    end
  end

在我的模板中,我有:

<%= simple_form_for(resource, :as => resource_name, :url => confirm_account_path(resource_name), :html => { :method => :put, :autocomplete => "off", :class => 'form-vertical' }) do |f| %>
  <%= devise_error_messages! %>
    <h1> Create your Account </h1>
    <%= f.input :first_name, :label => "First Name" %>
    <%= f.input :last_name, :label => "Last Name" %>
    <%= f.input :email, :label => "Email add." %>
  <p>
    <%= f.button :submit, "Create account" %>
  </p>
<% end %>

但是,当我点击“提交”按钮时,我会在日志中看到以下内容:

   (0.3ms)  BEGIN
  User Exists (0.5ms)  SELECT 1 AS one FROM "users" WHERE "users"."email" = 'myemail@gmail.com' LIMIT 1
   (0.3ms)  ROLLBACK
Completed 406 Not Acceptable in 5ms (ActiveRecord: 1.1ms)

为什么不让我尝试更新用户?

由于

1 个答案:

答案 0 :(得分:1)

因为你没有定义它。

在这里查看Devise :: RegistrationsController中的其他操作如何定义resourcehttps://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb