2014-10-28 57 views
0

红宝石v 1.9.3p194 轨v 3.1.3变化图像无刷新页面

我非常新的Ruby/Rails/JS我已经seaching了一段无果。如何从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 
+0

请在文本中包含你的问题也是如此。 – Fred 2014-10-28 14:31:25

+0

我问错了吗?有没有其他建议可以做到这一点? – 2014-10-28 18:36:08

回答

1

好做...答案是..

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