Rails jQuery 手风琴
如何设置 jQuery 来与 Rails 一起使用。我特别想使用手风琴功能。我之前在 PHP 中使用过这个,但我无法弄清楚 Rails 应用程序中的所有内容都需要放在哪里。我已将 jQuery 导入到 javascript 文件夹中并将其包含在应用程序中。我的 HTML 布局正确,但我不明白以下内容应该去哪里:
<script>
$(document).ready(function() {
$("#accordion").accordion();
});
</script>
我也尝试安装 jRails 并使用 scriptaculous Accordion,但它们都不起作用,所以我认为我缺少 javascript 和导轨。
我已经仔细寻找了一些关于如何设置它的明确说明,如果有人有链接或可以引导我完成它,我将不胜感激。
检查 firebug 后,我可以看到出现以下错误:
$("#accordion").accordion is not a function
I call jQuery before I call application.js
How do you set up jQuery to work with rails. I specifically want to use the accordion feature. I have used this before with PHP but i cannot work out where everything needs to go in a rails application. I have imported jQuery into the javascript folder and included it in the application. My HTML is laid out correctly, but i don't understand where the following should go:
<script>
$(document).ready(function() {
$("#accordion").accordion();
});
</script>
I have also tried installing jRails and using the scriptaculous Accordion, but neither of them worked either, so I think I am missing some vital link between javascript and rails.
I have looked all over for some explicit instructions on how to set it up, if anyone has a link or can walk me through it it would be appreciated.
After checking firebug I can see I am getting the following error:
$("#accordion").accordion is not a function
I call jQuery before I call application.js
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果你不想要 UJS 系统,你只需要把这一行放在你的视图中。
相反,您可以将其放在 application.js 上并在头节点中需要它。
You just need put this line in your view if you don't want UJS system.
Instead you can put it on your application.js and require it in your head node.
您还需要确保注释掉默认的 javascript 库,因为开箱即用的 Rails 应用程序附带原型,这将与您的 jQuery 库冲突。
它看起来像这样:
您在 firebug 中遇到任何 javascript 错误吗?
You also need to make sure that you commented out default javascript libraries, because out of the box, Rails applications come packaged with prototype which will conflict with your jQuery library.
It looks like this :
Are you hitting any javascript errors in firebug?