这是indexloc提供的服务,不要输入任何密码
Skip to content

Interference between Marketable Pages & ActiveStorage (Rails 5.2) #3383

@Obi-TOB

Description

@Obi-TOB

RefineryCMS (with Rails 5.2. support) in combination with SpreeCommerce 3.6.2:

When mounting Refinery in root

Rails.application.routes.draw do
  mount Spree::Core::Engine, at: '/shop'
  mount Refinery::Core::Engine, at: '/'
end

marketable_page routes interfere with ActiveStorage, i.e. the Refinery route matches and Refinery::PagesController takes over request:

Started GET "/rails/active_storage/disk/eyJf [...] g.jpeg" for 127.0.0.1 at 2018-07-20 21:31:58 +0200
Processing by Refinery::PagesController#show as JPEG
  Parameters: {"content_type"=>"image/jpeg", "disposition"=>"inline; filename=\"ror_bag.jpeg\"; filename*=UTF-8''ror_bag.jpeg", "path"=>"rails/active_storage/disk/eyJ [..] g", "locale"=>"en"}

I'm not really sure why this happens as the ActiveStorage routes are above the Refinery routes:

rake routes | grep 'pages#show\|rails'
[...]
rails_disk_service GET  /rails/active_storage/disk/:encoded_key/*filename(.:format)                              active_storage/disk#show
[...]
marketable_page GET    /*path(.:format)                           refinery/pages#show
[...]

Removing the mount point for Refinery or moving it to a different path however resolves the issue.

I resolve this now by a hacky route constraint in Refinery, however I would be interested why this happpens and how to resolve it 'right'.

def append_marketable_routes
  Refinery::Core::Engine.routes.append do
    get '*path', :to => 'pages#show', constraints: lambda { |req| !req.env["REQUEST_URI"].starts_with? "/rails/active_storage/" }, :as => :marketable_page
  end
end

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions