small medium large xlarge

Generic-user-small
19 Sep 2008, 19:01
Timo Goettel (3 posts)

Hi there, I am on rails 2.1.1 and try to get things done reading the 2nd edition of AWDwR…

After solving the ‘usual’ problems I am stuck on the shipping action…

I have defined an action in the controller (and a ship.html.erb) and I have tried many (many!) new routes in routes.rb but none of them helped in any case. Opening http://localhost:3000/books/ship (books instead of admin…) I still get this message

ActiveRecord::RecordNotFound in BooksController#show Couldn’t find Book with ID=ship

At the moment routes.rb says additionally : map.connect 'books/ship', :controller => "books", :action => "ship" </code rake routes tells me this:

          books GET    /books                           {:action=>"index", :controller=>"books"}
formatted_books GET    /books.:format                   {:action=>"index", :controller=>"books"}
                POST   /books                           {:action=>"create", :controller=>"books"}
                POST   /books.:format                   {:action=>"create", :controller=>"books"}
       new_book GET    /books/new                       {:action=>"new", :controller=>"books"}  formatted_new_book GET    /books/new.:format               {:action=>"new", :controller=>"books"}
      edit_book GET    /books/:id/edit                  {:action=>"edit", :controller=>"books"} formatted_edit_book GET    /books/:id/edit.:format          {:action=>"edit", :controller=>"books"}
           book GET    /books/:id                       {:action=>"show", :controller=>"books"}
 formatted_book GET    /books/:id.:format               {:action=>"show", :controller=>"books"}
                PUT    /books/:id                       {:action=>"update", :controller=>"books"}
                PUT    /books/:id.:format               {:action=>"update", :controller=>"books"}
                DELETE /books/:id                       {:action=>"destroy", :controller=>"books"}
                DELETE /books/:id.:format               {:action=>"destroy", :controller=>"books"}
                       /books/ship                      {:action=>"ship", :controller=>"books"}
                       /:controller/:action/:id         
                       /:controller/:action/:id.:format 

I think this looks fine?!

Is there anyone who suffered the same issues? Any help?

Thanks Timo let me know if you need further information…

Samr_small_pragsmall
19 Sep 2008, 23:44
Sam Ruby (634 posts)

GET /books/:id is before /books/ship, so the latter will never get a chance.

It looks like books is defined as a resource. If you want to add additional actions, add a :member parameter on the map.resources line itself. Look in chapter 20 for details.

Generic-user-small
20 Sep 2008, 15:31
Timo Goettel (3 posts)

Hi Sam,

thanks for your fast reply. I tried map.resources :books, :member => {:ship => :get} before…rake routes tells me this:

          books GET    /books                           {:action=>"index", :controller=>"books"}
formatted_books GET    /books.:format                   {:action=>"index", :controller=>"books"}
                POST   /books                           {:action=>"create", :controller=>"books"}
                POST   /books.:format                   {:action=>"create", :controller=>"books"}
       new_book GET    /books/new                       {:action=>"new", :controller=>"books"}  formatted_new_book GET    /books/new.:format               {:action=>"new", :controller=>"books"}
      edit_book GET    /books/:id/edit                  {:action=>"edit", :controller=>"books"} formatted_edit_book GET    /books/:id/edit.:format          {:action=>"edit", :controller=>"books"}
      ship_book GET    /books/:id/ship                  {:action=>"ship", :controller=>"books"} formatted_ship_book GET    /books/:id/ship.:format          {:action=>"ship", :controller=>"books"}
           book GET    /books/:id                       {:action=>"show", :controller=>"books"}
 formatted_book GET    /books/:id.:format               {:action=>"show", :controller=>"books"}
                PUT    /books/:id                       {:action=>"update", :controller=>"books"}
                PUT    /books/:id.:format               {:action=>"update", :controller=>"books"}
                DELETE /books/:id                       {:action=>"destroy", :controller=>"books"}
                DELETE /books/:id.:format               {:action=>"destroy", :controller=>"books"}
                       /:controller/:action/:id         
                       /:controller/:action/:id.:format 

looks like :id is stuck in there…any suggestions? cheers timo

Samr_small_pragsmall
20 Sep 2008, 18:10
Sam Ruby (634 posts)

My bad, I meant :collection.

Generic-user-small
20 Sep 2008, 20:44
Timo Goettel (3 posts)

Thank you very much Sam….

Problem solved :)

You must be logged in to comment