问题
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.
回答1:
Try including also PolymorphicRoutes
:
include ActionDispatch::Routing::PolymorphicRoutes
include Rails.application.routes.url_helpers
def link
polymorphic_path(self)
end
来源:https://stackoverflow.com/questions/27003252/how-can-i-access-polymorphic-path-inside-a-model-in-rails-4