开发者

Rails 3 Scaffolding, Adding Routes Question

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!


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜