kannathasan
kannathasan

Reputation: 573

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?

Upvotes: 5

Views: 3697

Answers (1)

Litmus
Litmus

Reputation: 10996

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

Upvotes: 3

Related Questions