i have a problem with ajax request:
in my app i am trying to configure a simple rank system, and i set it up, but whan i click on rank button – i reload the page and rank is refreshed.
Help my realize that in ajax:
i done that:
in posts/show.html.erb i have that:
<div id='vote_update'>
<%= render 'vote/update' %>
</div>
in vote/_update.html.erb i have :
<% if can? :update, Vote %>
<%= form_for([@post, @post.vote], remote: true) do |f| %>
...
<%= f.submit "vote" %>
in vote/update.js.erb i have:
$('#vote_update').html("<%= j render('vote/update') %>");
and in vote_controller.rb i have:
def update
post = Post.find(params[:post_id])
vote = post.vote
...
respond_to do |format|
if vote.save
format.html {
redirect_to post_path(post),
:notice => "You vote counted!"
}
format.js
end
end
end
if i remove romete: true – everything goes right ( page is reload, i saw (:notice) “You vote counted!” and rating is updated, but if i put remote: true back, i saw nothing ( some mistakes in firebug console ) – but when i reload page – ratign is updated, nd i saw norml result – i think i madesome mistakes in redirecting or i dont know
help please
your ajax code will come in format.js block. where you can update the html where you are showing the rank.