Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render partial in page from rails controller without prototype helpers

I'm removing Prototype from my Rails 3 app in exchange for jQuery and trying to figure out how my controller should update part of the html page without using this Prototype helper:

page.replace_html( "content", :partial => "day" )
like image 363
99miles Avatar asked Dec 16 '22 21:12

99miles


1 Answers

Since you've upgraded to Rails 3, you're on a great track to also stop using RJS. Use callbacks on the AJAX method to do the replacing. For example:

Ajax call:

$.ajax(
  url: "/things/one",
  type: "GET",
  complete: function(response, status) {
    $('#content').html(response);
  }
);

Then in the controller:

class ThingsController

  def one
    respond_to do |format|
      format.js { render :partial => "day" }
    end
  end

end
like image 68
jenjenut233 Avatar answered Mar 08 '23 23:03

jenjenut233