Ruby on rails 铁路3号线问题

Ruby on rails 铁路3号线问题,ruby-on-rails,routes,authlogic,Ruby On Rails,Routes,Authlogic,我是一名初级开发人员,我成功地使用了本教程“我在Rails 3中:允许用户重置密码”,但我也有一个客户模型需要这样做,我遇到了下面代码中列出的问题。我想这是我的路由错误,但我不知道如何修复它 routes.rb resources :password_resets do get 'edit_customer' post 'edit_customer' end 密码\u重置\u控制器.rb class PasswordResetsController < ApplicationCo

我是一名初级开发人员,我成功地使用了本教程“我在Rails 3中:允许用户重置密码”,但我也有一个客户模型需要这样做,我遇到了下面代码中列出的问题。我想这是我的路由错误,但我不知道如何修复它

routes.rb

resources :password_resets do
  get 'edit_customer'
  post 'edit_customer'
end
密码\u重置\u控制器.rb

class PasswordResetsController < ApplicationController
before_filter :load_user_using_perishable_token, :only => [:edit, :update]
before_filter :load_customer_using_perishable_token, :only => [:edit_customer, :update_customer]
before_filter :require_no_user, :require_no_customer

def new
render
end

def create
@user = User.find_by_email(params[:email])
@customer = Customer.find_by_email(params[:email])
if @user
  @user.deliver_password_reset_instructions!
  flash[:notice] = "Instructions to reset your password have been emailed to you. " +
    "Please check your email."
  redirect_to new_user_session_path
elsif
  if @customer
  @customer.deliver_customer_password_reset_instructions!
  flash[:notice] = "Instructions to reset your password have been emailed to you. " +
    "Please check your email."
  redirect_to new_customer_session_path
  end
else
  flash[:notice] = "No account was found with that email address"
  render :action => :new
end
end

def edit
render
end

def edit_customer
#redirect_to edit_customer_password_resets_path
end

def update
@user.password = params[:user][:password]
@user.password_confirmation = params[:user][:password_confirmation]
if @user.save
  flash[:notice] = "Password successfully updated"
  redirect_to new_user_session_path
else
  render :action => :edit
end
end

def update_customer
@customer.password = params[:customer][:password]
@customer.password_confirmation = params[:customer][:password_confirmation]
if @customer.save
  flash[:notice] = "Password successfully updated"
  redirect_to new_customer_session_path
else
  render :action => :edit
end
end

private
def load_user_using_perishable_token
  @user = User.find_using_perishable_token(params[:id])
  unless @user
    flash[:notice] = "We're sorry, but we could not locate your account." +
      "If you are having issues try copying and pasting the URL " +
      "from your email into your browser or restarting the " +
      "reset password process."
    redirect_to new_user_session_path
  end
end

def load_customer_using_perishable_token
  @customer = Customer.find_using_perishable_token(params[:id])
  unless @customer
    flash[:notice] = "We're sorry, but we could not locate your account." +
      "If you are having issues try copying and pasting the URL " +
      "from your email into your browser or restarting the " +
      "reset password process."
    #redirect_to new_customer_session_path
  end
end
end
customer.rb模型

def deliver_password_reset_instructions!
reset_perishable_token!
UserMailer.password_reset_instructions(self).deliver
end
def deliver_customer_password_reset_instructions!
 reset_perishable_token!
 UserMailer.customer_password_reset_instructions(self).deliver
end
观点 密码\u重置/新建

<% form_tag password_resets_path do %>
<p>Email:</p>
<%= text_field_tag "email" %><br />
<br />
<%= submit_tag "Reset my password" %>
<% end %>
密码\u重置/编辑

<% form_for @user, :url => password_reset_path, :method => :put do |f| %>
<%= f.label :password %><br />
<%= f.password_field :password %>
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation %>
<%= f.submit "Change my password and log me in"%>
<% end %>
密码\u重置/编辑\u客户

<% form_for @customer, :url => password_reset_path, :method => :put do |f| %>
<%= f.label :password %><br />
<%= f.password_field :password %>
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation %>
<%= f.submit "Change my password and log me in" %>
<% end %>
对于没有附加customer的代码,它非常适合。令牌生成,我可以获得与url相同格式的电子邮件:/password\u resets//edit\u customer

<% form_for @customer, :url => password_reset_path, :method => :put do |f| %>
<%= f.label :password %><br />
<%= f.password_field :password %>
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation %>
<%= f.submit "Change my password and log me in" %>
<% end %>
但是,当我尝试调出url时,它收到一个错误。通过上面的代码,我收到了这个错误:没有路由匹配{:action=>show,:controller=>password\u resets}-我还可以看到它将:id解释为控制器的id,这与用户id的工作方式不同-它正确地将id解释为令牌

我做了很多实验:

更改:控制器中的id,用于在load\u customer\u中使用\u易腐\u令牌编辑\u customer到易腐\u令牌,customer.易腐\u令牌,@customer.易腐\u令牌 尝试使用path helper=>cust\u pass-:path,:path\u name,:附加这些以获取“edit\u customer”,这样我就可以将url更改为cust\u pass\u path 我甚至试着把它添加到路线上,只是想看看它是否有效 匹配“/password\u resets/:id/edit\u customer”=>“password\u resetsedit\u customer”
所以我难倒了。任何帮助都将不胜感激

根据我的解释,你收到了电子邮件,但点击链接会给你一个错误?从错误消息开始

"No route matches {:action=>"show", :controller=>"password_resets"}"
出现的原因是您试图调用密码重置控件中的显示操作,但未定义该操作。您应该做的第一件事是将其从您的路线中排除

resources :password_resets, :except => :destroy do
  get 'edit_customer'
  post 'edit_customer'
end

我不认为它能解决你的问题,但是有一条没有出路的路线是毫无意义的。其次,确保你没有任何链接到表演动作。当您单击电子邮件中的链接时,错误似乎发生了,我认为您发送的链接不正确。

根据我的解释,您收到了电子邮件,但单击链接会给您一个错误?从错误消息开始

"No route matches {:action=>"show", :controller=>"password_resets"}"
出现的原因是您试图调用密码重置控件中的显示操作,但未定义该操作。您应该做的第一件事是将其从您的路线中排除

resources :password_resets, :except => :destroy do
  get 'edit_customer'
  post 'edit_customer'
end

我不认为它能解决你的问题,但是有一条没有出路的路线是毫无意义的。其次,确保你没有任何链接到表演动作。由于在您单击电子邮件中的链接时似乎出现了错误,我认为您发送的链接不正确。

我可以通过更新edit_customer.rb中的url来解决此问题

我还必须更新我的route.rb


我可以通过更新edit_customer.rb中的url来解决这个问题

我还必须更新我的route.rb


不要对post和get都使用一个操作。不要对post和get都使用一个操作。此外,我认为您需要为edit_customer和update_customer定义路由,并更新edit_customer表单以反映这一点。并且,在创建操作中,紧跟在elseif之后的if语句是多余的。您只需执行elseif@customeral即可。因此,我认为您需要为edit_customer和update_customer定义路由,并更新edit_customer表单以反映这一点。而在创建操作中,elseif之后的if语句是多余的。如果@customer,你可以做其他事情
resources :password_resets, :except => [:index, :destroy, :show] do
  get 'edit_customer'
  put 'update_customer'
end