vigetlabs/olive_branch

Add compatibility with Rails ActiveStorage

Closed this issue · 3 comments

olive_branch isn't compatible with rails's ActiveStorage out of box because transforms all /rails/active_storage/* responses to camelCase, when rails expects keys in lower_case here:

const { direct_upload } = response

https://github.com/rails/rails/blob/main/activestorage/app/javascript/activestorage/blob_record.js#L52

So it cause to error and doesn't allow to proceed with form submission:

activestorage.js:803 Uncaught TypeError: Cannot read property 'url' of undefined
    at new BlobUpload (activestorage.js:803)
    at BlobRecord.callback (activestorage.js:877)
    at BlobRecord.requestDidLoad (activestorage.js:752)
    at XMLHttpRequest.<anonymous> (activestorage.js:728)

My solution is to exclude /rails responses from olive_branch

    config.middleware.use(
      OliveBranch::Middleware,
      inflection: 'camel',
      exclude_response: lambda do |env|
        env['PATH_INFO'].match(%r{^/rails}) # exclude rails endpoints
      end
    )

Probably the solution deserves at least to be added to README.md to warn developers about that pitfall?

@itsNikolay thanks for the write up. Would you be comfortable submitting a PR with either a change to the core code, or a README update? We don't have anyone our team who's actively working on olive_branch these days.

@efatsi I added PR to exclude rails routes.
#48
Could you take a look? Thanks!

This is fixed in version 4.0.1. Thanks again @itsNikolay.