undefined method `user_path'

后端 未结 2 1426
星月不相逢
星月不相逢 2021-02-01 03:44

I am trying to construct a users model manually (without using \'resources :users\' in the routes.rb file). My routes.rb file looks like this:

match \'/users/:id         


        
2条回答
  •  广开言路
    2021-02-01 04:44

    match '/users/:id', :to => 'users#show' 
    

    should be

    match '/users/:id', :to => 'users#show', :as => :user
    

    The :as parameter tells the router what to name the route as (You can then add _path or _url to whatever the :as parameter is).

    Also, any time you link directly to an ActiveRecord model (e.g. link_to user.email, user), it will try to turn user into user_path.

提交回复
热议问题