我修改從伊莫雷諾卡瓦列羅答案因此它可以在軌道上5.1
只儲存你的觀點一樣
應用程序/視圖/大禮包/ first_store /家庭/ index.html.erb
應用程序/視圖/大禮包/ second_store /家庭/ index.html.erb
並添加此到config /初始化/ multi_domain.rb
module PartialRendererMultiStore
def find_template(path, locals)
prefixes = path.include?(?/) ? [] : @lookup_context.prefixes
store_prefixes = prefixes
store_path = path
if @view.respond_to?(:current_store) && @view.current_store && [email protected]_a?(Spree::Admin::BaseController)
store_prefixes = (store_prefixes.map { |i| i.gsub('spree/', "spree/#{@view.current_store.code}/") } + store_prefixes).uniq unless store_prefixes.nil?
store_path = store_path.gsub('spree/', "spree/#{@view.current_store.code}/") unless store_path.nil?
end
begin
@lookup_context.find_template(store_path, store_prefixes, true, locals, @details)
rescue ::ActionView::MissingTemplate
@lookup_context.find_template(path, prefixes, true, locals, @details)
end
end
end
class ActionView::PartialRenderer
prepend PartialRendererMultiStore
end
module TemplateRendererMultiStore
def find_template(name, prefixes = [], partial = false, keys = [], options = {})
if prefixes.nil?
store_prefixes = nil
elsif @view.respond_to?(:current_store) && @view.current_store && [email protected]_a?(Spree::Admin::BaseController)
spree = /^spree\//
store_prefixes = []
prefixes.each do |i|
store_prefixes << i.gsub(spree, "spree/#{@view.current_store.code}/") if i.match(spree)
end
store_prefixes = (store_prefixes + prefixes).uniq
else
store_prefixes = prefixes
end
begin
@lookup_context.find_template(name, store_prefixes, partial, keys, options)
rescue ::ActionView::MissingTemplate
@lookup_context.find_template(name, prefixes, partial, keys, options)
end
end
end
class ActionView::TemplateRenderer
prepend TemplateRendererMultiStore
end
spree_application
仍需views/spree/layouts/<store_code>/
去這類作品,但'alias_method_chain'在軌5.1現在已經過時。 – Qwertie