Rails url_for and namespaced models

前端 未结 4 1438
迷失自我
迷失自我 2020-12-29 08:13

In Rails, is it possible to namespace models in modules and still get correct behavior from url_for?

For instance, here, url_for works as e

4条回答
  •  情深已故
    2020-12-29 08:39

    In my case I overridden the url_for method on my application_helper.rb file to add the :network param on all routes from my namespace :mkp.

    module ApplicationHelper
      def url_for(options = {})
        if options.is_a?(Hash) && options.has_key?(:controller)
          if options[:network].nil? && options[:controller].match(/^mkp\//).present?
            options[:network] = @network.downcase
          end
        end
        super(options)
      end
    end
    

提交回复
热议问题