Undefined method `new_picture_path' Error

Hi All!
I have two models, Book and Picture,and Book can had many pictures ,so I
defined the relationship between them by follow code.

in Book:
has_many :pictures, :foreign_key => :resource_id, :conditions =>
“resource_type = ‘book’”

in Picture
belongs_to :book, :foreign_key => “resource_id”, :conditions =>
“resource_type = ‘book’”

in routes.rb, I add a few lines like this:

map.resources :books do |book|
book.resources :pictures
end

Ends up the url like “books/6/pictures/35.jpg” works fine,but when I add
a link in index view of Books:

<%= link_to “add a cover”, new_picture_path(book) %>

a undefine method error raise,the message told me these is no
new_picture_path method,why this happen?

Edward Bell wrote:

in routes.rb, I add a few lines like this:

map.resources :books do |book|
book.resources :pictures
end

<%= link_to “add a cover”, new_picture_path(book) %>

a undefine method error raise,the message told me these is no
new_picture_path method,why this happen?

Your picture routes are nested under books, so you would use:

new_book_picture_path(book)

Matt Haley wrote:

Your picture routes are nested under books, so you would use:

new_book_picture_path(book)

thanks Matt,now it works!