Rails routing: Giving default values for path helpers

℡╲_俬逩灬. 提交于 2019-12-03 03:46:22
CMW

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

u2622

In addition to CMW's answer, to get it to work with rspec, I added this hack in spec/support/default_url_options.rb

ActionDispatch::Routing::RouteSet.class_eval do
  undef_method :default_url_options
  def default_url_options(options={})
    { :current_brand => default_brand }
  end
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!