Search code examples
javascriptruby-on-railsrubyrjs

How to change html tag attribute value from RJS template?


Is it possible to change a html tag attribute value from an RSJ template? I know that there is a page.replace_html method, but it is not very useful in my case, since I have lengthy values of various attributes (such as alt, title of an image). What I want is change src attribute of a img tag in RJS. Is that possible at all?

Thank you.


Solution

  • EDIT: My first attempt didn't work, but this one does.

    update_page do |page|
      page['image_id']['src'] = new_image_url
    end