Git Product home page Git Product logo

Comments (5)

sherwinski avatar sherwinski commented on September 26, 2024 6

Hey everyone thanks for all the interest in this. We’ve received this question a couple of times in the past and with this issue being opened up, I decided it's finally time to give an established answer on the matter. The good news is that yes, imgix-rails does support ActiveStorage albeit it does require some configuring. The caveat to all this is that imgix cannot process images stored locally with ActiveStorage, as it can only be used with remote sources.
To set up imgix with ActiveStorage, first ensure that the remote source your ActiveStorage service is pointing to is the same as your imgix source — such as an s3 bucket.

# config/storage.yml
service: S3
access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
region: us-east-1
bucket: your_own_bucket

Modify your active_storage.service setting depending on what environment you are using. For example, to use Amazon s3 in production, make the following change:

# config/environments/production.rb
config.active_storage.service = :amazon

As you would normally with imgix-rails, configure your application to point to your imgix source:

# config/application.rb
Rails.application.configure do
      config.imgix = {
        source: your_domain,
        use_https: true,
        include_library_param: true
      }
end

Finally, the two can be used together by passing in the filename of the ActiveStorage blob into the imgix-rails helper function:

# show.html.erb
<%= ix_image_tag(@your_model.image.key) %>

from imgix-rails.

dwightwatson avatar dwightwatson commented on September 26, 2024

I'm also curious about this - ActiveStorage performance can be pretty ordinary for public assets, it seems like putting Imgix in front of it would solve that problem while also giving you greater control over the transformations.

from imgix-rails.

Lewiscowles1986 avatar Lewiscowles1986 commented on September 26, 2024

Trying to use with ActiveStorage, even with a path I get the following

"exception":{"name":"ActionView::Template::Error","message":"undefined method `[]=' for nil:NilClass"
imgix/rails/tag.rb:22

from imgix-rails.

phildionne avatar phildionne commented on September 26, 2024

Awesome! Thanks for the walkthrough @sherwinski !

from imgix-rails.

Lewiscowles1986 avatar Lewiscowles1986 commented on September 26, 2024

Yeah, so I also fixed the bug I mentioned above, although I had to fix it in a weird way, partly it was that we were trying to pass named args with splat to a helper that decides if things should go to imgix or rails default image_tag, managing the API differences. Two args I insisted should default to nil instead of {} I chose to not splat args in helper method and also to wrap the Rails.application.configure in a conditional (local-dev we just won't get the benefits of Imgix) and ensure imgix always gets what it needs.

Thank you so much @sherwinski for responding on this.

from imgix-rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.