views:

26

answers:

1

Hello, rails 3 newbie, with a general question about adding an additional route after scaffolding.

I create a scaffold for books... Which works great, and provides a nice index page.

The Index page shows all books in the system, I'd like to add a page '/books/yours' that shows the books the user created. I already added the user_id to the books table, so that's working when users create new books. But I can't figure out how to add the 'yours' page... Here's what I did:

In the books_controller.rb added:

  def yours
        @books = Books.all

        respond_to do |format|
      format.html # yours.html.erb
     format.xml  { render :xml => @notes }
    end
  end

Then I added a views/books/yours.html.erb page with just an H1 tag that says bingo...

Then in routes.rb I added:

Cline::Application.routes.draw do

  resources :books
  devise_for :users
    match '/books/yours', :to => 'books#yours'
    root :to => 'pages#home'

But it doesn't work? What'd I do wrong? thxs!

+2  A: 

Hi,

you could do this:

resources :books do  
  collection do  
    get 'yours'  
  end 
end 

So the url looks like: /books/yours

Here's everything explained: http://edgeguides.rubyonrails.org/routing.html

sled
@Sled you're a rock start. thanks man
AnApprentice