10

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
  • 19,887
  • 29
  • 98
  • 154

2 Answers2

20
include Rails.application.routes.url_helpers
def notification_content   
  "#{listing_url(my_listing, :host => "example.com")}. " + ...
end
clyfe
  • 23,695
  • 8
  • 85
  • 109
4

(From the comments, credit to Edward Anderson)


Prepend url_for with:

Rails.application.routes.url_helpers.*url_for(...)*
Shiva
  • 11,485
  • 2
  • 67
  • 84
Shark Lasers
  • 441
  • 6
  • 15