页面替换为 RJS
我尝试在我的一个 Rails 项目中实现投票功能。我使用以下代码(在 vote.rjs 中)将页面替换为部分模板 (_vote.rhtml)。但是当我点击时,投票数无法立即更新。我必须刷新页面才能看到更改。
vote.rjs
page.replace("votes#{@foundphoto.id}", :partial=>"vote", :locals=>{:voteable=>@foundphoto})
部分模板如下:
_vote .rhtml
“>
<%= link_to_remote "+(#{voteable.votes_for})",
:update="投票",
:网址=> { :action="投票",
:id=>voteable.id,
:投票=>“支持”} %>
/
<%= link_to_remote "-(#{voteable.votes_against})",
:update="投票",
:网址=> { :action="投票",
:id=>voteable.id,
:投票=>“反对”} %>
有什么想法吗?谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请使用 firebug 检查响应,我相信对服务器的调用已成功进行,并且它也在更改数据。如果您在development.log中发现任何错误,请发布,尝试通过给出一个简单的
请在vote.rjs中保留上述行来测试您的应用程序,看看您是否收到一些警报。
如果您的development.log文件中没有错误,那么您可能忘记了在页面中包含javascript,或者您正在使用jquery javascript库但忘记安装jrails。
请发布一次日志以明确此问题。
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
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.
您的代码中是否包含 "prototype.js" ?
Do you include "prototype.js" in your code ?