Partial does not render with 'enter' using Ajax

0

I have an ajax that fires when the page loads:

/assets/javascript/itens.js :

if ($('#content-recommendation').length) {
    xhr = $.ajax({
    url:'/get_recommendations/' + gon.item_id + '.js',
    type:"get"
  });
}

views/items/show :

<div id="content-recommendation" class="col-md-3">
  <p>hey!</p>
</div>

itens_controller#get_recommendation :

def get_recommendations
  respond_to do |format|
     format.js
  end
end

itens/get_recommendations.js.erb :

$("#content-recommendation").html("<%= render 'content_recommendation'%>")

_content_recommendation.html.erb :

<h3>Ultimos itens visitados:</h3>
<p>teste</p>

This is by far the strangest problem I found in RoR. If I put in _content_recommendation.html.erb :

<h3>Ultimos itens visitados:</h3><p>teste</p>

(without spaces) it works ...

    
asked by anonymous 01.09.2014 / 03:39

1 answer

1

In get_recommendations.js.erb was missing escape_javacript :

$("#content-recommendation").html("<%= escape_javascript(render 'content_recommendation', itens: @itens_recomendados ) %>")

More information on this link

    
01.09.2014 / 04:15