Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 225
Florent2 Avatar asked Sep 02 '10 16:09

Florent2


2 Answers

Got an answer from the rails IRC: just add

  include Rails.application.routes.url_helpers 

to your model

like image 194
Florent2 Avatar answered Oct 11 '22 15:10

Florent2


In Rails 3 you can use:

Rails.application.routes.url_helpers 

e.g.

Rails.application.routes.url_helpers.posts_path 
like image 29
hrdwdmrbl Avatar answered Oct 11 '22 14:10

hrdwdmrbl