Ask A Question


You’re not receiving notifications from this thread.

problem with like link in nested resource

Pablo Seo asked in Rails

Hi Chris im doing the episode 'liking posts' i have difficult to do with deep nested resource,
my actual nested resources looks:

A. Routes:

  resources :users do
      resources :catalogs do
          resources :pages do
              resources :types do
                  resources :like, module: :types

B. link:

= link_to 'Like', [current_user, @catalog, @page, @type, @like], method: :post

C. Rake Routes:

user_catalog_page_type_like_index GET    /users/:user_id/catalogs/:catalog_id/pages/:page_id/types/:type_id/like(.:format)       types/like#index                                                   ____________________________ POST   /users/:user_id/catalogs/:catalog_id/pages/:page_id/types/:type_id/like(.:format)      types/like#create  new_user_catalog_page_type_like  GET     /users/:user_id/catalogs/:catalog_id/pages/:page_id/types/:type_id/like/new(.:format)      types/like#new
 edit_user_catalog_page_type_like GET     /users/:user_id/catalogs/:catalog_id/pages/:page_id/types/:type_id/like/:id/edit(.:format) types/like#edit
      user_catalog_page_type_like GET         /users/:user_id/catalogs/:catalog_id/pages/:page_id/types/:type_id/like/:id(.:format)      types/like#show
                                  PATCH  /users/:user_id/catalogs/:catalog_id/pages/:page_id/types/:type_id/like/:id(.:format)      types/like#update
                                  PUT    /users/:user_id/catalogs/:catalog_id/pages/:page_id/types/:type_id/like/:id(.:format)      types/like#update
                                  DELETE /users/:user_id/catalogs/:catalog_id/pages/:page_id/types/:type_id/like/:id(.:format)      types/like#destroy

The link is not working, have any idea?

Thank you!


Hey Pablo,

Your link looks correct and so do your routes. Are you getting an error?


when i click i got this error message:

POST http://localhost:5000/users/modas-sol/catalogs/13/pages/10/types/24 404 (Not Found)


Oh of course. If you look at your routes, there is no POST paths there. I think you can change the resources :like to be singular instead like this: resource :like and that will help.

In either case, your rake routes should be creating a POST link to let you create a new like. It's odd that your current one doesn't have a POST route.

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 79,047+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2023 GoRails, LLC. All rights reserved.