views:

33

answers:

4

How can I get a full url in rails?

url_for @book is returning only a path like /book/1 and not www.domain.com/book/1

Thanks (and sorry if the answer is obvious. Im learning rails!)

A: 

Did you try path_for?

Tass
says: undefined method `path_for' for #<ActionView::Base:0x1042750b0>
Victor P
Oke. just an educated guess. :-)
Tass
A: 

Use the :host option. For example, you can use:

url_for(@book, :host => "domain.com")
vegetables
A: 

If it's a RESTful resource you'll be able to use this:

book_url(@book)
Ryan Bigg
A: 

According to the docs, this shouldn't happen. The option you're looking for is :only_path and it's false by default. What happens if you set it to false explicitly?

url_for(@book, :only_path => false)

While you can use url_for you should prefer Ryan's method when you can - book_url(@book) for a full url or book_path(@book) for the path.

Andy Gaskell