This seems to work:
url_for(@book)
But this is not so. The url_for method accepts only one argument, which can be either a string, or an instance of a model, or an hash of options. This is pretty unfortunate, since it looks like you might need a link to @book and add options like: only_path or: host.
One way is to use polymorphic_url, which will display the correct absolute URL, even if your model (most likely) is not actually polymorphic:
polymorphic_url(@book, :host => "domain.com")
Perhaps the best route would be to use a named route, which is automatically set for you when you declare resources on your routes or using the: as option:
# in routes.rb: resources :books # or get "books/:id" => "books#show", as: :book # in your view: book_path(@book, :host => "domain.com")
a moose Jan 20 '13 at 4:30 2013-01-20 04:30
source share