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
<%= sel开发者_如何学JAVAection[: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 is what you need
$("selected").update("<%= escape_javascript(render :partial => '/results/academics', :locals => { :selection => @selection }) %>")
精彩评论