简体   繁体   中英

ActionView::Template::Error (No route matches {} missing required keys: [:id])

The error is:

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]):

I think the problem is in the html code:

 <%= link_to 'Profile', user_path(current_user) %>

 <%= link_to 'Upload Meter Data', user_path(current_user) %>

But it works correctly in local. The problem only happened in heroku.

My 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'

How to solve this problem?

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

尝试这个:

/\d/ change to /\d+/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM