How to render images in Javascript with Rails 3.1

Rails 3.1 now requires use image_tagwhen rendering an image using the asset pipeline.

I created an infinite scroll in my application and put the code in the js.coffee file. I want to make a rotating boot gif while loading more products. I cannot use it image_taghere, because this file does not support rails code, but I wrote it here so that you understand what I'm trying to do.

jQuery ->
  if $('.pagination').length
    $(window).scroll ->
      url = $('.pagination .next_page').attr('href')
      if url && $(window).scrollTop() > $(document).height() - $(window).height() - 1200
        $('.pagination').html("<%= image_tag("loading.gif") %> Loading more...")
        $.getScript(url)
    $(window).scroll()

I used to just write it in pure HTML using <img src=...But this will no longer work with the asset pipeline. How can I achieve this?

+5
source share
1 answer

HTML .

: <img src="/assets/loading.gif" />, loading.gif assets/images.

21/06/2012

Ruby on Rails Guide, 2.2.3, .js filename.js.erb filename.js.coffee.erb javascript.

asset_path , .

+5

All Articles