简体   繁体   English

带有JS代码的Rails中的错误

[英]Error in Rails with JS code

Rails will not let me run JS code, I have these errors Rails不会让我运行JS代码,我有这些错误

1) 1)

在此处输入图片说明

2) 2)

在此处输入图片说明

whenever you add JS code, the errors appear. 每当添加JS代码时,都会出现错误。 Some idea why this happening? 知道为什么会这样吗?

Just because you're getting error highlights in your IDE, doesn't necessarily mean your code is wrong. 仅仅因为您在IDE中得到了错误提示,并不一定意味着您的代码是错误的。 Try running your server, navigate to your site from your browser, and check the developer console. 尝试运行服务器,从浏览器导航到您的站点,然后检查开发人员控制台。 Do you still see javascript errors? 您仍然看到JavaScript错误吗?

This warning (it is not an error) is being displayed because your IDE thinks that the variable $ is not defined in your code. 正在显示此警告(不是错误),因为您的IDE认为代码中未定义变量$ However, it is not able to find out that $ is a global variable defined in the jQuery library, imported a few lines before. 但是,无法发现$是jQuery库中定义的全局变量,之前已导入了几行。

The IDE is just saying that the presence of that variable is not guaranteed unless you properly import the needed libraries to make it exist (jQuery in this case). IDE只是说不能保证该变量的存在,除非您正确导入所需的库以使其存在(在本例中为jQuery)。 Your code should work properly. 您的代码应该可以正常工作。 In order to identify errors in your javascript code, I would recommend you to use the built in console in the web browser. 为了识别JavaScript代码中的错误,建议您在网络浏览器中使用内置控制台。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM