Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get url_for an object in Model method in Rails

I would like to create a string that include a path for an object in Rails.

  def notification_content   
      "#{app.listing_url(my_listing, :host => "example.com")}. " +
  end

This content will then be fed into my ActionMailer as email content.

In console, it works fine. However, when I run it on localhost server, I get the following error:

undefined local variable or method `app'

How should I go about it? Also, how can I make the path to be a hyperlink?

Thanks a lot.

like image 871
AdamNYC Avatar asked Jan 03 '12 00:01

AdamNYC


1 Answers

include Rails.application.routes.url_helpers
def notification_content   
  "#{listing_url(my_listing, :host => "example.com")}. " + ...
end
like image 178
clyfe Avatar answered Oct 02 '22 09:10

clyfe