Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get url of object in controller

Tags:

I've got a Product model.

How do I get the url of a product in Rails 3, in a controller.

For example (pseudo code):

def foobar   @product = Product.first   puts @product.url end 

Is such a thing possible?

like image 414
Christian Fazzini Avatar asked May 06 '11 07:05

Christian Fazzini


Video Answer


1 Answers

Assuming the Product model is mapped as :resources in your routes.rb file:

def foobar   @product = Product.first   url = product_url(@product) end 
like image 157
Simone Carletti Avatar answered Sep 29 '22 21:09

Simone Carletti