如何在Rails 4中访问模型内的polymorphic_path? [英] How can I access polymorphic_path inside a model in Rails 4?
本文介绍了如何在Rails 4中访问模型内的polymorphic_path?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
非常简单,我想在Rails 4模型中使用 polymorphic_path
方法。是的,我知道关注点分离不良。而且我知道 Rails.application.routes.url_helpers
,但是 polymorphic_path
不在其中。
Pretty simple, I want to use the polymorphic_path
method inside a Rails 4 model. Yes I know it's poor separation of concerns. And I know about Rails.application.routes.url_helpers
, but polymorphic_path
isn't in there.
推荐答案
尝试还包括 PolymorphicRoutes
:
include ActionDispatch::Routing::PolymorphicRoutes
include Rails.application.routes.url_helpers
def link
polymorphic_path(self)
end
这篇关于如何在Rails 4中访问模型内的polymorphic_path?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文