Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use page.replace_html in rails 4

Hi currently I am upgrading my project from rails 3.2 to rails 4. After upgrading to rails 4. page.replace_html method is not working property.

eg:

In controller if it encountered code like this,

render :update do |page|

page.replace_html "lease_container", :partial => "/lease/property_pipeline", :locals => {:note_collection => @note}

end

it throws error like this,

ActionView::MissingTemplate (Missing template lease/update, application/update with {:locale=>[:en], :formats=>[:js, :html, :xml, :html, :text, :js, :css, :ics, :csv, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip], :handlers=>[:erb, :builder, :raw, :ruby, :rjs]}

how could i resolve this?. Is there any alternative to do this with jquery?

like image 484
kannathasan Avatar asked Oct 20 '22 21:10

kannathasan


1 Answers

use prototype-rails helper gem

Still better, refactor the code to use jQuery. Rails now encourages UJS (Un Obtrusive JavaScript). So an exact replacement syntax in jQuery may not be desirable.

You can try something like this

$("#divid").html("<div>all the html goes here</div>") 

This will replace the contents of a <div id="divid">....</div> with what is passed into .html("....")

Here is the jQuery documentation for .html()

There is a nice RailsCasts Episode #205 on this topic

like image 147
Litmus Avatar answered Nov 01 '22 15:11

Litmus