# Undefined method \`new\_picture\_path' Error

**URL:** <https://www.ruby-forum.com/t/undefined-method-new-picture-path-error/145615>\
**Category:** Rails\
**Created:** [August 12, 2008, 5:30am UTC](https://www.ruby-forum.com/t/undefined-method-new-picture-path-error/145615 "2008-08-12T05:30:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://www.ruby-forum.com/u/bell)\
**Post date:** [August 12, 2008, 5:30am UTC](https://www.ruby-forum.com/t/undefined-method-new-picture-path-error/145615/1 "2008-08-12T05:30:04Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![bell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://www.ruby-forum.com/u/bell)\
**Post date:** [August 12, 2008, 7:42am UTC](https://www.ruby-forum.com/t/undefined-method-new-picture-path-error/145615/2 "2008-08-12T07:42:09Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![bell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://www.ruby-forum.com/u/bell)\
**Post date:** [August 12, 2008, 10:46am UTC](https://www.ruby-forum.com/t/undefined-method-new-picture-path-error/145615/3 "2008-08-12T10:46:10Z")

</div>

Matt Haley wrote:

> Your picture routes are nested under books, so you would use:
> 
> new\_book\_picture\_path(book)

thanks Matt,now it works!
