如何在rails 3中定义自己的路由助手?

abo*_*nec 5 routes ruby-on-rails custom-routes

我使用polimorphic_path并且它有些马车.此方法需要一些未定义的路由助手.我如何定义(像常规方法)自己的路由助手将使用像"model_name_path,model_name_url等"?

Ben*_*Ben 2

我知道 _path 的一个可能答案,但对于 _url 来说,这对我不起作用。有人知道为什么吗?

# at the bottom of config/routes.rb
module ActionView::Helpers::UrlHelper
    def model_name_path model, args={}
        # your implementation
    end
end
Run Code Online (Sandbox Code Playgroud)