Replace_html 后的 Visual_effect 在 rjs 中不起作用
在学习 Ruby on Rails 过程中,我创建了一个博客网站。当用户通过 AJAX 添加帖子时,将调用以下 rjs:
page.replace_html 'posts', :partial => @posts
page.visual_effect :Highlight, 'post_' + @post.id.to_s
然而,突出显示并未发生.. 也没有任何效果,甚至隐藏。
线索:
- 如果我只执行 insert_html 就可以了 只是为了新帖子(但我想要 更新整个帖子列表 此时)
- 如果我将 id 硬编码为序列中的下一个 id,它不会在该帖子上起作用,但会在下一个帖子上起作用。 { 例如.. 硬编码 post_100... 提交 100 上没有突出显示,提交 101 上突出显示 100 }
- 警报显示 'post_' + @post.id.to_s 是预期的( post_100 等)
有任何想法或调试建议吗?
谢谢, 奥兰多
In learning ruby on rails I've created a blog site. When the user adds a post via AJAX, the following rjs gets called:
page.replace_html 'posts', :partial => @posts
page.visual_effect :Highlight, 'post_' + @post.id.to_s
However, the highlight isn't happening.. neither is any sort of effect even a hide.
Clues:
- It works if I just do an insert_html
for just the new post (but I want
to update the whole list of posts
at this time) - If I hard code the id to the next id in the sequence, it doesn't work on the post, but it does work on the next post. { ex.. hardcode post_100... no highlight on submit 100, highlight 100 on submit 101 }
- Alert shows that 'post_' + @post.id.to_s is what is expected ( post_100, etc )
Any ideas or debugging suggestions?
Thanks,
Orlando
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你能在视觉效果之前提醒 $("post_#{@post.id}") 的innerHTML吗?
当 firebug 到达 Visual_effect 时,它会给你一个错误吗?
您可以做其他事情,例如在 Visual_effect 行之后发出警报吗?
你有需要的js文件吗?
Can you alert the innerHTML of the $("post_#{@post.id}") before the visual_effect.
Does firebug give you an error when it gets to the visual_effect?
Can you do something else, like an alert after the visual_effect line?
Have you got the required js files included?
这并不是问题的真正答案,但我已经不再依赖 rjs。相反,我遵循此处概述的模式
http://blog.solnic.eu/2007/10/30/why-javascript-helpers-in-rails-are-evil
现在所有效果都按预期工作。请注意,当使用实际上应该在此处工作的相同代码添加注释时,我确实获得了效果,因此我相当确信只是发生了某种奇怪的操作员错误。
It's not really an answer to the problem, but I have since done away with reliance on rjs. Instead I'm following the pattern outlined here
http://blog.solnic.eu/2007/10/30/why-javascript-helpers-in-rails-are-evil
And now all effects are working as expected. Note that I did get the effect working when comments were added using effectively the same code that should have been working here, so I'm fairly convinced there was just some sort of weird operator error going on.