Partial does not render with enter using Ajax

Asked

Viewed 52 times

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. I put myself in _content_recommendation.html.erb:

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

(no spaces) it works...

1 answer

1


In get_recommendations.js.erb was missing escape_javacript:

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

You have more information on this link

  • Awkward, consider marking your answer as correct by clicking left below the score. Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.