Reputation: 2941
I have a Rails app in which I have a list of items. Each item have it's own like button. When clicking this like button I perform some Ajax / Javascript to update the status. I'm having some issues with getting the correct button to update.
My like button looks like this:
div_for(idea) do
- if current_user.voted_for? idea
= render "ideas/unlike_button", idea: idea
- else
= render "ideas/like_button", idea: idea
My like.js.erb file currently looks like this:
$("#<%= idea_#{@idea.id} %>").html("<%= j render partial: 'ideas/unlike_button', locals: {idea: @idea} %>");
I don't think this is working as I want: "#<%= idea_#{@idea.id} %>"
What I want is "idea_123"
.
How can I achieve that?
Upvotes: 1
Views: 424
Reputation: 4251
Instead of
$("#<%= idea_#{@idea.id} %>").html("Your code");
Try:
$("#idea_<%= @idea.id %>").html("your code");
Upvotes: 3