Comments (5)
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.
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.
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.
Awesome! Thanks for the walkthrough @sherwinski !
from imgix-rails.
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)
- Updating imgix-rb dependency to v4? HOT 2
- ssrf external service interaction to malicious external source - security issue HOT 8
- `ix_image_url` doesn't work with fingerprinted assets anymore HOT 3
- Usage with multiple sources? HOT 1
- Multiple secure_url_tokens when using multiple sources HOT 3
- max_width not working HOT 4
- Support Multiple Sources HOT 4
- data-srcset instead of srcset HOT 5
- Switching between dev (local filesystem) and production (aws s3) HOT 2
- SemVer? Changelog? HOT 4
- ix_picture_tag provides wrong ouput of v3 HOT 1
- extra srcset link generated causes issue on non-retina displays HOT 1
- bundler restricted to version <2.0
- Support latest version of imgix-rb HOT 1
- How to use inside a model? HOT 9
- `min_width` and `max_width` are rendered to HTML tag HOT 1
- Digest hash HOT 3
- Getting static image instead of GIF HOT 4
- data attributes instead of plain srcset, src, sizes attribute HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imgix-rails.