This is my view: (show.html.erb
)
<%=link_to vote_for, vote_for_question_path(@question), :remote => true%>
This is the action that the link calls in the question_controller
:
def vote_for
@quest_vote_for = Question.find(params[:id])
current_user.vote_exclusively_for(@quest_vote_for)
@total_vote = current_user.total_votes
respond_to do |format|
format.js{}
format.html
end
end
What I want, is to update the content of the show.html.erb after the link is clicked. (I am using ajax (remote=>true
)). The show.html.page should update itself with the new value of @total_vote
.
How can I do this?
Add vote_for.js.erb, then add the following content to your file:
$("body").prepend("<h1><%= @total_vote %></h1>")