Florent2
Florent2

Reputation: 3513

How to use routing helpers in a model with Rails 3?

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 :)

Upvotes: 23

Views: 10589

Answers (2)

hrdwdmrbl
hrdwdmrbl

Reputation: 5269

In Rails 3 you can use:

Rails.application.routes.url_helpers

e.g.

Rails.application.routes.url_helpers.posts_path

Upvotes: 17

Florent2
Florent2

Reputation: 3513

Got an answer from the rails IRC: just add

  include Rails.application.routes.url_helpers

to your model

Upvotes: 31

Related Questions