简体   繁体   English

如何在Rails 3的模型中使用路由助手?

[英]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. 在模型回调中,我进行API调用,并且需要为API提供一些URL。 Those URLs would be easily generated by a routing helper. 这些URL很容易由路由助手生成。

The solution given in this answer does not work anymore in Rails 3. 在这个答案中给出的解决方案在Rails 3中不再起作用。

Any solution? 有解决方案吗 Thanks :) 谢谢 :)

Got an answer from the rails IRC: just add 从轨道IRC得到答案:只需添加

  include Rails.application.routes.url_helpers

to your model 到你的模型

In Rails 3 you can use: 在Rails 3中,您可以使用:

Rails.application.routes.url_helpers

eg 例如

Rails.application.routes.url_helpers.posts_path

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM