2017-04-16 111 views
-1

我試圖通過單擊激活電子郵件鏈接添加註冊確認。電子郵件發送,但是當我點擊鏈接,它說該頁面不存在。部署在heroku上。 樣品確認鏈接:Ruby on Rails - 用戶電子郵件驗證頁面不存在

/account_activations/g_dTGV1CbHip7w3w76pqCQ/edit?email=utn49585%40disaq.com 

它看起來像應用程序犯規承認這條道路。我檢查了,激活摘要(g_dTGV1CbHip7w3w76pqCQ)存儲在數據庫中。我不知道什麼會導致這樣的錯誤。

account_activation.html.erb:

Click the link below in order to activate your account 
<%= edit_account_activation_url(@user.activation_token, email: @user.email)%> 

account_activation.text.erb:

Click the link below in order to activate your account 
<%= edit_account_activation_url(@user.activation_token, email: @user.email)%> 

routes.rb中:

Rails.application.routes.draw do 
root 'welcome#home' 
get '/login', to: 'sessions#new' 
post '/login', to: 'sessions#create' 
delete '/logout', to: 'sessions#destroy' 
resources :users 
resources :account_activations, only: [:edit] 
end 

全github上: https://github.com/mateusz208345/Ror-My-App

+0

你檢查日誌嗎? –

+0

你確定你點擊的鏈接是最近發送的嗎? –

+0

您的回購鏈接已損壞:(我看不到您的其他應用程序 – Gaston

回答

0

更改this line到:

user = User.find_by(email: params[:email]) 
       ^^^ 

爲什麼?

User.find(email: params[:email])實際上是指:「查找其id{:email => "[email protected]"}用戶

我怎麼弄明白

我發起了在開發模式的應用:?我創建了一個

bin/rails db:migrate RAILS_ENV=development 
bin/rails server 

用戶,並在日誌中看到此電子郵件已呈現:

<!DOCTYPE html> 
<html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <style> 
     /* Email styles need to be inline */ 
    </style> 
    </head> 

    <body> 
    Click the link below in order to activate your account https://rails-tutorial-firel.c9users.io/account_activations/nK69XMp3floxtPhV1Jwskg/edit?email=utn49585%40disaq.com 
    </body> 
</html> 

然後我去:http://localhost:3000/account_activations/nK69XMp3floxtPhV1Jwskg/edit?email=utn49585%40disaq.com

見到了這個錯誤:

ActiveRecord::RecordNotFound in AccountActivationsController#edit 
Couldn't find User with 'id'={:email=>"[email protected]"} 

在生產環境中,如Heroku的,ActiveRecord::RecordNotFound errors are treated as 404這可能會產生誤導。

更改我在回答開頭提到的這一行修復了這個特定的錯誤。