Render partial with Ajax!

Discussion in 'Ruby' started by robzdc, Apr 4, 2013.

  1. #1
    So I had some issues with an App I'm doing, I was calling an entire template...
    The problem was that when you call a template, you load all the libraries with it... its just crap.
    So I create a partial to just call the partial for every search, without the libraries or anything that I don't need.
    To do that you must specify the partial in the respond_to like this
    
    respond_to do |format|
          format.html { render :partial => 'partials/results' } # index.html.erb
          format.json { render json: @results, :callback => params[:callback] }
    end
    
    Code (markup):
    And with jquery you just call the data
    
    $.get "/search/result", data, (data) ->
          $("#resultados").html data
    
    Code (markup):
    Maybe some of you already know that, but I'm just letting this here so maybe it can be helpful to someone else.
     
    robzdc, Apr 4, 2013 IP