简体   繁体   中英

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. I'm using link_to to update a 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):

*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. 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. What am I doing wrong?

escape_javascript是您需要的

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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