-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image assets #193
Comments
Hey! Here is what I currently use: Put this in your application helper: def image_assets
image_asset_dir = Rails.root.join('app', 'assets', 'images')
assets = {}
%w(.jpg .png .jpeg .svg).each do |file_ext|
Dir.glob(File.join(image_asset_dir, "**", "*#{file_ext}")).each do |absolute_path|
file = absolute_path.sub(File.join(image_asset_dir, '/'), '')
assets[file] = asset_url(file)
end
end
assets
end Add this to you /app/assets/javascripts/assets.js.erb: <% environment.context_class.instance_eval { include ApplicationHelper } %>
window.assets = window.assets || {};
window.assets.images = <%= raw(image_assets.to_json) %>; Create a helper: return window.assets.images[params[0]]; then you can do something like this in your template: <img src="{{asset-path 'login.png'}}"> EDIT: This isnt my code, I found it somewhere online and set it up in my application |
@nahtnam Thanks a lot for taking the time to reply, and for the code! I eventually decided to not use When developing, I run both:
When in development, Rails won't serve any index HTML. It will be served by the ember Express server. This way, I also make it simpler to play with Now, when deploying, to make things simpler (yeah, I know there are better ways to do that, such as storing the index HTML in Redis, etc), I just build the ember app with the help of a helper sh script, I borrowed from here: https://github.com/knomedia/ember-cli-rails It builds the app, lets Cheers! |
For me, the perfect scenario would be to have rails s boot up both the rails and ember server (like it does now), but when I deploy it, it compiles it and moves to to the public folder or to rails application.html.erb... |
What's the recommended way to deal with image assets? Since Sprockets helpers like
image-path
- which are pretty much needed because of assets fingerprinting on production - are only available in Rails-rendered views, what's the suggested solution to be able to reference images from the Rails pipeline fromhbs
views (rendered by Ember)?I can imagine a couple of hacks for doing that, but the question is: Does ember-cli-rails already implement (or recommend) something?
Thanks!
The text was updated successfully, but these errors were encountered: