Alex Rivera | Logout

Full URL with url_for in Rails

Asked 2010-08-16T00:17:34.843
25

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!)

Edit
Report

1 Answer

68

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.

answered 2010-08-16T01:12:09.680

Your Answer