spree-multi-domain
spree-multi-domain copied to clipboard
Domain Logo not saved
When i save a logo for a domain, it is not saved. Going back into the admin screen shows the image is 404 - its looking for the right file, but can't find it. I've recreated this issue using both the pow server, and just in webrick & going to localhost:3000
ActionController::RoutingError (No route matches [GET] "/images/stores/2/medium/happydog.jpg"):
ActionController::RoutingError (No route matches [GET] "/images/stores/2/medium/happydog.jpg"):
vendor/bundle/gems/actionpack-4.0.5/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
vendor/bundle/gems/actionpack-4.0.5/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
vendor/bundle/gems/railties-4.0.5/lib/rails/rack/logger.rb:38:in `call_app'
vendor/bundle/gems/railties-4.0.5/lib/rails/rack/logger.rb:20:in `block in call'
vendor/bundle/gems/activesupport-4.0.5/lib/active_support/tagged_logging.rb:68:in `block in tagged'
vendor/bundle/gems/activesupport-4.0.5/lib/active_support/tagged_logging.rb:26:in `tagged'
vendor/bundle/gems/activesupport-4.0.5/lib/active_support/tagged_logging.rb:68:in `tagged'
vendor/bundle/gems/railties-4.0.5/lib/rails/rack/logger.rb:20:in `call'
vendor/bundle/gems/actionpack-4.0.5/lib/action_dispatch/middleware/request_id.rb:21:in `call'
vendor/bundle/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
vendor/bundle/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
vendor/bundle/gems/activesupport-4.0.5/lib/active_support/cache/strategy/local_cache.rb:83:in `call'
vendor/bundle/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call'
vendor/bundle/gems/actionpack-4.0.5/lib/action_dispatch/middleware/static.rb:64:in `call'
vendor/bundle/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
vendor/bundle/gems/railties-4.0.5/lib/rails/engine.rb:511:in `call'
vendor/bundle/gems/railties-4.0.5/lib/rails/application.rb:97:in `call'
vendor/bundle/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call'
vendor/bundle/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
vendor/bundle/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
/Users/willbarker/.rbenv/versions/2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/Users/willbarker/.rbenv/versions/2.1.2/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/Users/willbarker/.rbenv/versions/2.1.2/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
Rendered vendor/bundle/gems/actionpack-4.0.5/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.2ms)
Rendered vendor/bundle/gems/actionpack-4.0.5/lib/action_dispatch/middleware/templates/routes/_route.html.erb (0.9ms)
Rendered vendor/bundle/gems/actionpack-4.0.5/lib/action_dispatch/middleware/templates/routes/_route.html.erb (158.6ms)
Rendered vendor/bundle/gems/actionpack-4.0.5/lib/action_dispatch/middleware/templates/routes/_table.html.erb (1.5ms)
Rendered vendor/bundle/gems/actionpack-4.0.5/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (441.3ms)
gemfile.lock: https://gist.github.com/asecondwill/16309d43e0ae36787a44
I think you can workaround the issue as follows:
- in app/helpers/spree/base_helper_decorator.rb:
module Spree
module BaseHelper
def logo(image_path = current_store.logo.url)
link_to image_tag(image_path), spree.root_path
end
end
end
- in app/models/spree/store_decorator.rb:
Spree::Store.class_eval do
# For the default_url, assume Spree is mounted at '/' in your routes.rb
has_attached_file :logo,
styles: { mini: '48x48>', small: '100x100>', medium: '250x250>' },
default_style: :medium,
default_url: "/assets/#{Spree::Config[:logo]}",
url: '/spree/stores/:id/:style/:basename.:extension',
path: 'public/spree/stores/:id/:style/:basename.:extension',
convert_options: { :all => '-strip -auto-orient' }
# Required for Paperclip 4+
# change the pattern to whatever suits your needs
validates_attachment :logo,
file_name: { matches: [/\A.+\.png\z/, /\A.+\.jpe?g\z/] }
end
It's not very flexible, but worked for me.