我尝试在rails帮助器中设置一些选项,但似乎每次都被覆盖。
module MetaTagHelper
def meta_options
@meta_options ||= {}
end
def add_meta_tag_options(opt)
meta_options.deep_merge(opt)
end
end
这是测试
require 'rspec'
describe MetaTagHelper do
it 'options should be set' do
option = {region: "1"}
option2 = {country: "AT"}
helper.add_meta_tag_options(option)
helper.add_meta_tag_options(option2).should eql(option.merge option2)
end
end
expected: {:region=>"1", :country=>"AT"}
got: {:country=>"AT"}
如何获得规格传递?
答案 0 :(得分:1)
尝试使用deep_merge!:
def add_meta_tag_options(opt)
meta_options.deep_merge!(opt)
end