Skip to main content
Ask A Question
Notifications
You’re not receiving notifications from this thread.
Subscribe

problem with like link in nested resource

Rails • Asked by Pablo Seo

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
              end
          end
      end
  end

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?



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.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,353+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.