2015-09-14 94 views
2

的錯誤是:::的ActionView ::模板錯誤(沒有路由匹配{}缺少必需的鍵:[:編號])

ActionView::Template::Error (No route matches {:action=>"show", :controller=>"users", :id=>#<User id: 21, name: "Test", email: "[email protected]", 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' 

如何解決這個問題呢?

回答

2
resources :users, only: [:show], constraints: { id: /\d/ } 

試試這個:

/\d/ change to /\d+/ 
相關問題