23

In a model callback I make an API call and need to give the API some URLs. Those URLs would be easily generated by a routing helper.

The solution given in this answer does not work anymore in Rails 3.

Any solution? Thanks :)

Community
  • 1
  • 1
Florent2
  • 3,247
  • 3
  • 23
  • 36

2 Answers2

31

Got an answer from the rails IRC: just add

  include Rails.application.routes.url_helpers

to your model

Florent2
  • 3,247
  • 3
  • 23
  • 36
  • 3
    this may cause an infinite loop error. If so you, can use delegate, i.e `delegate :url_helpers, to: 'Rails.application.routes'` – Ben Feb 16 '13 at 21:32
17

In Rails 3 you can use:

Rails.application.routes.url_helpers

e.g.

Rails.application.routes.url_helpers.posts_path
hrdwdmrbl
  • 4,275
  • 1
  • 29
  • 33