ember-rails
ember-rails copied to clipboard
Figure out how to support something like asset-pipeline-aware `{{imageURL}}`
Not sure I follow... you mean something to convert src="{{imageURL hello.jpg}}" to src="/assets/hello-98werfegerg.jpg" ?
I've got a very naive implementation of this I've been working on.
It involves an {{imageTag}} helper which looks up an Ember.Images hash.
Currently loading in the Ember.Images hash via the HTML, but was planning on looking into the feasibility of using Sprockets, once I get sometime to clean it up
What problem does this solve? Why wouldn't the image urls be available as part of a model or some other dynamic data?
Site images, I've extracted as much as I can to CSS background images, but there's only so far you can go.
Is there any recommendation for this issue? I first ran into this when attempting to add logo.svg to my application.hbs template.
I can place the logo image in app/assets/images/logo.svg and then reference it using <img src="/assets/logo.svg">, but when the app is precompiled, the compiled handlebars js file still references /assets/logo.svg instead of the actual /assets/logo-64240dd6f2216d4dfac944c2165531b5.svg.
I'm currently loading it via an ENV variable, stripped down example below:
application_helper.rb
def preload_env
env = {}
env["ASSETS"] = asset_hash
...
env
end
def asset_hash
{
wysihtml5: javascript_path("wysihtml5-0.3.0"),
blank_avatar: image_path("avatars/avatar-blank.png"),
vendor_avatar: image_path("avatar-vendor-big.png"),
user_avatar: image_path("avatar-user-big.png"),
company_avatar: image_path("avatar-company-big.png"),
product_placeholder: image_path("product-placeholder.png")
}
end
index.html.erb
<%= javascript_tag("window.ENV = #{preload_env.to_json.html_safe}") %>
application.hbs
<img src="{{unbound Ember.ENV.ASSETS.blank_avatar}}"/>
I appreciate your help on this @bradleypriest. Very nice solution; tried it out and it worked perfectly!
This is an interesting approach but why is it necessary? We're in Rails, just append .erb to the end of your handlebars template name and use the asset_path helper. Unless I'm missing something :)
<img src="<%= asset_path('special-image.png') %>" class="icon" alt="special image">
:+1: to @supairish
Don't know why something so obvious was stumping me. Thanks for the tip!
@supairish solution is simple and pragmatic, but for various reasons it wouldn't work for us. So, if you really need an asset-path helper like I did: https://github.com/botandrose/ember-rails-assets