开发者

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

开发者 https://www.devze.com 2023-01-15 02:21 出处:网络
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.

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


Got an answer from the rails IRC: just add

  include Rails.application.routes.url_helpers

to your model


In Rails 3 you can use:

Rails.application.routes.url_helpers

e.g.

Rails.application.routes.url_helpers.posts_path
0

精彩评论

暂无评论...
验证码 换一张
取 消