728x90 AdSpace

Thursday, September 18, 2014

Rails: Render partials via ajax without load the page


Normally, we render partials via views by using render [partial_without_underscore]. But we can also render partials in our document using ajax.
To do this we need to

Create an action method that we would call to load the partial and write the following code inside the action method

layout: false will disable the loading of layouts and headers we create.
partial: “partial_form” will load the partial “_partial_form.html.erb” file.
respond_to do |format|
format.html { render partial: "partial_form", layout: false }
end
Now make an ajax call to url controller/action
 
Grab the data via HTTP response and render in the webpage



Also read:
  • Blogger Comments
  • Facebook Comments

2 comments:

Item Reviewed: Rails: Render partials via ajax without load the page Rating: 5 Reviewed By: PCSO Lotto Results