0
votes

I have routes defined to some static pages and also to some controllers (users and usymptoms). When I navigate to localhost:3000/users/1 or localhost:3000/users/1/usymptoms/new everything is fine. Once I finish filling in the form on symptoms/new, I have the usymptoms controller redirecting to @users. This works fine.

In the model file, the association is users has many usymptoms and usymptoms belongs to user.

However, now my static pages are not accessible. For example, when I navigate to /learn, I get the following error:

No route matches {:action=>"new", :controller=>"usymptoms", :user_id=>nil}

I am new to rails. Can you please help me figure out the error?

I have provided my routes file and the output from "rake routes" below.

My routes.rb file

root to: 'static_pages#home'
match '/about',   to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
match '/learn',   to: 'static_pages#learn'

match '/signup',  to: 'users#new'
match '/signin',  to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete

resources :users do
  resources :usymptoms
end


resources :sessions, only: [:new, :create, :destroy]

======

Output from rake routes

              root        /                                            static_pages#home
             about        /about(.:format)                             static_pages#about
           contact        /contact(.:format)                           static_pages#contact
             learn        /learn(.:format)                             static_pages#learn
            signup        /signup(.:format)                            users#new
            signin        /signin(.:format)                            sessions#new
           signout DELETE /signout(.:format)                           sessions#destroy
    user_usymptoms GET    /users/:user_id/usymptoms(.:format)          usymptoms#index
                   POST   /users/:user_id/usymptoms(.:format)          usymptoms#create
 new_user_usymptom GET    /users/:user_id/usymptoms/new(.:format)      usymptoms#new
edit_user_usymptom GET    /users/:user_id/usymptoms/:id/edit(.:format) usymptoms#edit
     user_usymptom GET    /users/:user_id/usymptoms/:id(.:format)      usymptoms#show
                   PUT    /users/:user_id/usymptoms/:id(.:format)      usymptoms#update
                   DELETE /users/:user_id/usymptoms/:id(.:format)      usymptoms#destroy
             users GET    /users(.:format)                             users#index
                   POST   /users(.:format)                             users#create
          new_user GET    /users/new(.:format)                         users#new
         edit_user GET    /users/:id/edit(.:format)                    users#edit
              user GET    /users/:id(.:format)                         users#show
                   PUT    /users/:id(.:format)                         users#update
                   DELETE /users/:id(.:format)                         users#destroy
          sessions POST   /sessions(.:format)                          sessions#create
       new_session GET    /sessions/new(.:format)                      sessions#new
           session DELETE /sessions/:id(.:format)                      sessions#destroy
1
Do /learn (or other static pages) work before adding symptoms? Do you have any links to new_user_usymptom in the application layout (or other shared)? - Sam Peacey
Please post your controller code. - Chris Salzberg

1 Answers

0
votes

You must have the following link somewhere: new_user_usymptom_path(@user), but @user is nil for some reason, hence the error.