Reputation: 553
In my comments/_questions partial I have a list of links for each question. You can post a new link with ajax but it starts acting wonky (scrolls to the bottom of the page, submit button stops working) if you've posted a link on another question on the same page. I think this is because I'm using the same class to reload the links partial.
So, to solve this I attached '-<%= question.id %>' to the '#linkpartial' id. This gives me an 'undefined local variable or method `question'' error in links/create.js.erb.
Links/create.js.erb
$('#linkpartial-<%= question.id %>').html("<%= j (render :partial => 'comments/newlink', locals: {question: @question}) %>");
Comments/_question.hml.erb
<% @questions.each do |question| %>
<div id ="linkpartial-<%= question.id %>">
<%= render :partial => 'links', locals: {question:question} %>
</div>
<% end %>
How do I pass in a question from the comments/_questions partial to links/create.js.erb?
Upvotes: 1
Views: 900
Reputation: 2707
Looks like you are missing a @ in $('#linkpartial-<%= question.id %>')
$('#linkpartial-<%= @question.id %>').html("<%= j (render :partial => 'comments/newlink', locals: {question: @question}) %>");
Upvotes: 4