Rails routing: Giving default values for path helpers

后端 未结 2 1258
梦如初夏
梦如初夏 2021-02-06 13:31

Is there some way to provide a default value to the url/path helpers?

I have an optional scope wrapping around all of my routes:

#config/routes.rb
Foo::A         


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-06 13:40

    I think you will want to do something like this:

    class ApplicationController < ActionController::Base
    
      def url_options
        { :current_brand => @current_brand }.merge(super)
      end
    
    end
    

    This method is called automatically every time url is constructed and it's result is merged into the parameters.

    For more info on this, look at: default_url_options and rails 3

提交回复
热议问题