简体   繁体   English

无法使用Rails和Prototype渲染多条线

[英]Unable to render more than one line using Rails and Prototype

I'm having a really odd problem (which usually means I'm doing something wrong) with rails 3.0.5 and prototype. 我在rails 3.0.5和prototype上遇到了一个非常奇怪的问题(通常意味着我做错了什么)。 I'm using link_to to update a div: 我正在使用link_to更新div:

*views/results/index.html.erb
<%= link_to "#{school[:name]}", {:controller => "results", :action => "update", :school => school}, :remote => true%>

This calls the controller function update: 这将调用控制器功能更新:

*controllers/results_controller.rb
def update
  @selection = params[:school]
  respond_to do |format|
    format.html {redirect_to :action => 'index'}
    format.js
  end
end

Which renders update.js.erb ('selected' is a div in index.html.erb): 呈现update.js.erb(“ selected”是index.html.erb中的div):

*views/results/update.js.erb
$("selected").update("<%= render :partial => '/results/academics', :locals => { :selection => @selection } %>")

Here's where it gets strange. 这就是奇怪的地方。 If my partial academics.html.erb includes just one line of plain text, it works just fine. 如果我的部分cademics.html.erb仅包含一行纯文本,则效果很好。 For example: 例如:

*views/results/academics.html.erb
<%= selection[:chances] %>

works fine. 工作正常。 but if i have more than one line, it doesn't. 但是,如果我有多条线,那就没有。 For example: 例如:

*views/results/academics.html.erb
<%= selection[:chances] %>
<br>

Renders nothing. 什么都不渲染。 Server still responds with 200 OK, but div doesn't change. 服务器仍然以200 OK响应,但是div不变。 What am I doing wrong? 我究竟做错了什么?

escape_javascript是您需要的

$("selected").update("<%= escape_javascript(render :partial => '/results/academics', :locals => { :selection => @selection }) %>")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM