Page replace with RJS
I try to implement a vote feature in one of my rails projects. I use the following codes (in vote.rjs) to replace the page with a Partial template (_vote.rhtml). But when I click, the vote number can not be updated immediately. I have to refresh the page to see the change.
vote.rjs
page.replace("votes#{@foundphoto.id}", :partial=>"vote", :locals=>{:voteable=>@foundphoto})
The partial template is as follows:
_vote.rhtml
">
<%= link_to_remote "+(#{voteable.votes_for})", :update=>"vote", :url => { :action=>"vote", :id=>voteable.id, :vote=>"for"} %> / <%= link_to_remote "-(#开发者_开发问答{voteable.votes_against})", :update=>"vote", :url => { :action=>"vote", :id=>voteable.id, :vote=>"against"} %>any ideas? Thanks.
Do you include "prototype.js" in your code ?
Please use firebug to check the response, I believe the call to the server is made successfully and it is changing the data as well. Please post if you find any errors in your development.log, try testing your application by giving a simple
page.alert "some alert"
please keep the above line in your vote.rjs and see if you are getting some alert.
If there is no error in your development.log file then you might have forgotten to include the javascripts inside the page or if you are using jquery javascript library but forgot to install jrails.
Please post your log once to be clear on this question.
精彩评论