设计确认无法在最新版本中使用

时间:2011-10-31 12:42:58

标签: ruby-on-rails ruby-on-rails-3 authentication devise

我最近从Devise 1.2升级到1.4.9,除了我的确认模块外,一切似乎都有效。电子邮件以及整个过程都有效。但确认页面始终为空白。它工作并确认电子邮件帐户,但它不会重定向用户并引发406错误。对于错误确认尝试,它也是如此。

路由似乎工作正常,我在我的用户模型中指定了确认,并且没有其他任何更改。

有什么想法吗?我是否缺少一些设置或需要为1.4.9更新的内容?

更新

生成URL似乎有问题。由于某些未知原因,它是在前面加上确认URL和用户名吗?这导致它破裂。但我仍然不确定如何解决它。

http://localhost:5000/users/confirmation.someusername?confirmation_token=R7apAPhC5c3rszvhsowp

上述网址中的用户名导致该流程无效。

我检查了1.2(有效)控制器和新版本之间的差异。

1.2

  # GET /resource/confirmation?confirmation_token=abcdef
  def show
    self.resource = resource_class.confirm_by_token(params[:confirmation_token])

    if resource.errors.empty?
      set_flash_message :notice, :confirmed
      sign_in_and_redirect(resource_name, resource)
    else
      render_with_scope :new
    end
  end

1.4.9

  # GET /resource/confirmation?confirmation_token=abcdef
  def show
    self.resource = resource_class.confirm_by_token(params[:confirmation_token])

    if resource.errors.empty?
      set_flash_message(:notice, :confirmed) if is_navigational_format?
      sign_in(resource_name, resource)
      respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
    else
      respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render_with_scope :new }
    end
  end

  protected

    # The path used after resending confirmation instructions.
    def after_resending_confirmation_instructions_path_for(resource_name)
      new_session_path(resource_name)
    end

    # The path used after confirmation.
    def after_confirmation_path_for(resource_name, resource)
      after_sign_in_path_for(resource)
    end

错误

Started GET "/users/confirmation.sdfsdfsd?confirmation_token=vmxmx73xvM7sUfcvH9CX" for 127.0.0.1 at 2011-10-31 13:30:33 +0100
  Processing by Devise::ConfirmationsController#show as 
  Parameters: {"confirmation_token"=>"vmxmx73xvM7sUfcvH9CX"}
  SQL (1.1ms)   SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
 FROM pg_attribute a LEFT JOIN pg_attrdef d
 ON a.attrelid = d.adrelid AND a.attnum = d.adnum
 WHERE a.attrelid = '"users"'::regclass
 AND a.attnum > 0 AND NOT a.attisdropped
 ORDER BY a.attnum

  User Load (1.2ms)  SELECT "users".* FROM "users" WHERE "users"."confirmation_token" = 'vmxmx73xvM7sUfcvH9CX' LIMIT 1
  SQL (0.7ms)   SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
 FROM pg_attribute a LEFT JOIN pg_attrdef d
 ON a.attrelid = d.adrelid AND a.attnum = d.adnum
 WHERE a.attrelid = '"users"'::regclass
 AND a.attnum > 0 AND NOT a.attisdropped
 ORDER BY a.attnum

Completed 406 Not Acceptable in 28ms

5 个答案:

答案 0 :(得分:7)

其他人指出了我正确的方向,但这是我的确切解决方案。问题出在我从1.2中复制的设计视图模板中?看起来他们已将链接助手从user_confirmation_url()更改为simply confirmation_url()

旧确认电子邮件

<p>Welcome <%= @resource.email %>!</p>

<p>You can confirm your account through the link below:</p>

<p><%= link_to 'Confirm my account', user_confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>

新确认模板

<p>Welcome <%= @resource.email %>!</p>

<p>You can confirm your account through the link below:</p>

<p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>

答案 1 :(得分:5)

查看并查看是否复制了设计视图,它们可能已过期。

我的网址中有一个类似的issue奇怪的用户ID,设计不再使用user_confirmation_url支持confirmation_url(从1.0开始?,但它仍然有点长一点)因此您可以删除自定义设计视图或更新网址助手。

答案 2 :(得分:1)

最新的设计代码是

<p><%= link_to 'Confirm my account', model_confirmation_url(:confirmation_token => @model.confirmation_token) %></p>

版本
设计-2.1.2

答案 3 :(得分:0)

对于我的情况,我在视图/设计下有自定义视图,例如views / devise / confirmations / new.html.erb using users_confirmation_url。我将这些错误移到了views / users下并使用了confirmation_url后,我没有再收到任何错误。

答案 4 :(得分:0)

对于我的情况(Rails 4.2和设计3.4.1)

修复生成的视图(在app / views / devise / mailer / confirmation_instructions.html.erb中)需要将user_confirmation_url中的@resource删除为:

@token)%&gt;

相关问题