我如何将其添加到rjs?

时间:2012-02-12 17:34:02

标签: ruby-on-rails ruby-on-rails-3 rjs

我有这个命令,我知道语法有点偏离

 page << "$('.places').append('<%= escape_javascript(render(:partial => 'contact', :locals => {:contact => @contact, :something => @something, :checked => false, :sale => @sale.item.to_s})) %>');"    

这是我需要做的基本调用,但我知道js.rjs文件的语法错误....有没有办法将其转换为该格式

1 个答案:

答案 0 :(得分:1)

使用原型(Rails 2.3)

page.select(".places").each  do |element, index|
  page.insert_html :bottom, element, :partial => 'contact', :locals => {:contact => @contact, :something => @something, :checked => false, :sale => @sale.item.to_s}
end

使用jQuery(Rails 3)

$(".places").append("<%= escape_javascript render 'contact', :locals => {:contact => @contact, :something => @something, :checked => false, :sale => @sale.item.to_s} %>");