Rails: getting a β€œnew” path for a nested resource

I have a nested resource that looks like this on my routes:

resource :reviews do resource :entries end 

I am trying to create a link for a new recording path as follows:

 <%= link_to "New Entry", new_review_entry_path(@review) %> 

Sorry, I keep getting this error message:

 undefined method `new_review_entry_path' for #<#<Class:0x5150d78>:0x483c798> 

I checked the rake routes and it turned out that the route should be pluralized in:

 new_reviews_entries_path(@review) 

Unfortunately, when I do this, I get an odd URL:

 /reviews/entries/new.1 

Obviously this will not work either. Any idea what is going on here?

+6
source share
1 answer

These are resources , not resource . Your first attempt was correct;)

 resources :reviews do resources :entries end 

You must use resource when the resource is "unique." For example, if a user has one profile, you would do:

 resources :users do resource :profile end 
+7
source

All Articles