![](/img/trans.png)
[英]ActionView::Template::Error (No route matches {:action=>“show”, :controller=>“categories”, :id=>nil} missing required keys: [:id]):
[英]ActionView::Template::Error (No route matches {} missing required keys: [:id])
錯誤是:
ActionView::Template::Error (No route matches {:action=>"show", :controller=>"users", :id=>#<User id: 21, name: "Test", email: "test@gmail.com", encrypted_password: "$2a$10$UE170rpnHsdnTOMfBC190uiHQ/ygmLkRxfsTaRMBBT/...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2015-09-14 04:11:22", last_sign_in_at: "2015-09-14 04:11:22", current_sign_in_ip: #<IPAddr: IPv4:128.250.1.8/255.255.255.255>, last_sign_in_ip: #<IPAddr: IPv4:128.250.1.8/255.255.255.255>, created_at: "2015-09-14 04:11:22", updated_at: "2015-09-14 04:11:22">} missing required keys: [:id]):
我認為問題出在 html 代碼中:
<%= link_to 'Profile', user_path(current_user) %>
<%= link_to 'Upload Meter Data', user_path(current_user) %>
但它在本地工作正常。 問題只發生在heroku中。
我的route.rb
:
devise_for :users, controllers: { registrations: "users/registrations" }
get 'users/import' => 'users#upload_nem12'
post 'users/import' => 'users#import_nem12'
# user's show page
# get 'users/:id' => 'users#show'
resources :users, only: [:show], constraints: { id: /\d/ }
get 'users/profile' => 'users#show'
如何解決這個問題呢?
resources :users, only: [:show], constraints: { id: /\d/ }
嘗試這個:
/\d/ change to /\d+/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.