Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 设计可确认的路由问题-仅电子邮件注册,获取错误“;不能';t查找id为“确认”的用户;_Ruby On Rails 3_Routes_Devise Confirmable - Fatal编程技术网

Ruby on rails 3 设计可确认的路由问题-仅电子邮件注册,获取错误“;不能';t查找id为“确认”的用户;

Ruby on rails 3 设计可确认的路由问题-仅电子邮件注册,获取错误“;不能';t查找id为“确认”的用户;,ruby-on-rails-3,routes,devise-confirmable,Ruby On Rails 3,Routes,Devise Confirmable,我想我和Desive之间有一个无法解决的路由问题。我正在尝试实现让用户使用Desive注册以进行身份验证。这个例子使用了haml,我尝试将其翻译回erb,希望能取得一些成功 使用PostgresQL在Mac OS X上开发Rails 3.2.8 使用design和simple_形式 app/views/designe/registrations/new.html.erb: <%= simple_form_for(resource, :as => resource_name, :url

我想我和Desive之间有一个无法解决的路由问题。我正在尝试实现让用户使用Desive注册以进行身份验证。这个例子使用了haml,我尝试将其翻译回erb,希望能取得一些成功

使用PostgresQL在Mac OS X上开发Rails 3.2.8 使用design和simple_形式

app/views/designe/registrations/new.html.erb:

<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%# simple_form_for([:backend, @user]) do |f| %>
  <%= f.error_notification %>

  <div class="inputs">
    <%= f.input :email, :required => true, :autofocus => true, :label => "Email" %>
  </div>

  <div class="actions">
    <%= f.button :submit, "Add User" %>
  </div>
<% end %>
<%= simple_form_for(resource, :as => resource_name, :url => confirmation_path(resource_name)) do |f| %>
<div class="inputs">
    <%= f.input :password, :required => true, :label => "Password" %>
    <%= f.input :password_confirmation, :required => true, :label => "Confirm Password" %>
    <%= f.hidden_field :confirmation_token %>
</div>
<div class="actions">
  <%= f.button :submit, "Confirm" %>
</div>
<% end %>
class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :confirmable,
         :timeoutable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email,
                  :password,
                  :password_confirmation,
                  :remember_me,
                  :username

  def password_required?
    super if confirmed?
  end

  def password_match?
    self.errors[:password] << "can't be blank" if password.blank?
    self.errors[:password_confirmation] << "can't be blank" if password_confirmation.blank?
    self.errors[:password_confirmation] << "does not match password" if password != password_confirmation
    password == password_confirmation && !password.blank?
  end

end
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
end
  devise_for :users, :controllers => {:confirmations => 'confirmations'}

  devise_scope :user do
    put "/confirm" => "confirmations#confirm"
  end

  resources :users
当我在用户/注册页面输入电子邮件地址时,一切正常。我收到确认电子邮件,单击确认链接并被定向到:

/用户/确认?确认令牌=[此处的确认令牌]

然后,当我填写密码并提交时,我会被引导到该页面:

用户/确认

出现以下错误:

ActiveRecord::在UsersController更新中未找到RecordNot 找不到id=确认的用户


我很确定这是一个路由问题。有什么想法吗?非常感谢

赛尔,谢谢你今晚让我的大脑工作起来。答案一直盯着我的脸。在路线上,我改变了

match "/confirm" => "confirmations#confirm"


现在我可以开始研究它抛出的下一个错误了。再次感谢

重定向似乎有问题,只是在黑暗中拍摄,但您能否尝试将您的简单表单中的url更改为“`:url=>确认路径(参考资料)`谢谢您的建议,但这不起作用。为了清楚起见,您建议将views/devise/confirmations/show.html.erb:resource_name,:url=>confirmation_path(resource_name))do | f |%>中的这一行更改为:resource_name,:url=>confirmation_path(resource))do | f |%>?在我看来,确认控制器永远不会被调用。相反,rails路由到用户控制器中的show操作,这就是错误所在?您可以尝试在确认操作中删除
调试器
语句作为断点,以确保正在调用它。如果出于任何原因您没有调试设置,也可以选择抛出垃圾代码并查看是否触发异常。还要确保确认操作中的
render:action=>“show”
正在呈现确认控制器的show操作,而不是用户控制器。
match "/confirmation" => "confirmations#confirm"