9

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.

AdamNYC
  • 17,771
  • 28
  • 90
  • 147

2 Answers2

17
include Rails.application.routes.url_helpers
def notification_content   
  "#{listing_url(my_listing, :host => "example.com")}. " + ...
end
clyfe
  • 23,035
  • 7
  • 78
  • 106
2

(From the comments, credit to Edward Anderson)


Prepend url_for with:

Rails.application.routes.url_helpers.url_for(...)

Shark Lasers
  • 383
  • 4
  • 13