【问题标题】:change image in partial from js.erb without refresh of page从 js.erb 更改部分图像而不刷新页面
【发布时间】:2014-10-28 14:28:08
【问题描述】:

红宝石 v 1.9.3p194 轨道 v 3.1.3

我对 ruby​​/rails/js 很陌生,我已经搜索了一段时间但无济于事。如何从 capture_photo.js.erb 更新两个图像?

我正在使用 js 从网络摄像头捕获图像并将其设置为用户头像。图像存储在 Patient.photo_uid 中。

我以 2 个部分显示图像,并希望在保存后更新这两个图像。我想我想从我的 capture_photo.js.erb 中做到这一点

//relevant sidbar.html.haml:
  %a#user_sidebar_image{href: "javascript:void(0)"}
  = image_tag user_avatar_url(current_patient, "thumb")

//relevant _patient_info.html.haml:
  %img.img-polaroid{:src => "#{photo}", alt: "Patient avatar image"}


//relevant capture_photo.js.erb:
  <% if @success == true %>
    //I want to set picture here

【问题讨论】:

  • 请在正文中也包含您的问题。
  • 我问错了吗?有什么建议可以换一种方式吗?

标签: ruby-on-rails ruby haml erb


【解决方案1】:

好吧……答案是……

 <% if @success == true %>
 $('#user_sidebar_image > img').attr('src', "<%= @patient.photo.try(:url) %>")
 $('.thumbnail-container > img').attr('src', "<%= @patient.photo.try(:url) %>")

【讨论】:

    猜你喜欢
    • 2014-06-24
    • 2016-06-10
    • 2011-02-04
    • 1970-01-01
    • 2010-12-26
    • 2016-09-03
    • 2015-08-08
    • 1970-01-01
    • 2014-04-07
    相关资源
    最近更新 更多