NoMethodError in Books#index

hi i have books_controller(action new index show create update..) by scaffolding and i add these lines to my program

****books_controller action def buy     @book = Book.find(params[:id])     @book.user = current_user end

****routes.rb   map.resources :books, :collection => { :buy => :get }

****books_ index.html.erb <%= link_to 'buy', buy_book_path(book) %>

but when i am logging to books_index page

NoMethodError in Books#index undefined method `buy_book_path' for #<ActionView::Base:0x64a45b0> why i'm getting this error?

hi i have books_controller(action new index show create update..) by scaffolding and i add these lines to my program

****books_controller action def buy @book = Book.find(params[:id]) @book.user = current_user end

****routes.rb map.resources :books, :collection => { :buy => :get }

****books_ index.html.erb <%= link_to 'buy', buy_book_path(book) %>

but when i am logging to books_index page

NoMethodError in Books#index undefined method `buy_book_path' for #<ActionView::Base:0x64a45b0> why i'm getting this error?

Because the name of the route is buy_books (because you've said that the buy verb applies to the collection of books as a whole). If you change your routes stuff to :member => {:buy => :get} then you'll get buy_book instead of buy_book. (Remember that you can see the names of all the routes by running rake routes)

Fred