【问题标题】:javascript_include_tag throws unsupported methodjavascript_include_tag 抛出不受支持的方法
【发布时间】:2015-04-30 18:35:38
【问题描述】:

我最近使用 Rails 4.2.0 创建了一个新项目,并为登录页面创建了一个名为 Land 的控制器。所以,我在访问http://localhost:3000/land/home 时遇到了这个错误:

Started GET "/" for ::1 at 2015-02-27 15:56:23 -0600
Processing by LandController#home as HTML
Rendered land/home.html.erb within layouts/application (0.0ms)
Completed 500 Internal Server Error in 5526ms

ActionView::Template::Error (TypeError: Object doesn't support this property or method
(in C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/turbolinks-2.5.3/lib/assets/javascripts/turbolinks.js.coffee)):
3: <head>
4:   <title>Course</title>
5:   <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
6:   <%= javascript_include_tag 'application' %>
7:   <%= csrf_meta_tags %>
8: </head>
9: <body>
app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb__1279127835_98590860'


Rendered C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/_source.erb (5.0ms)

Rendered C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/_trace.html.erb (10.0ms)

Rendered C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/_request_and_response.html.erb (1.0ms)

Rendered C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/_web_console.html.erb (2.0ms)

Rendered C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/web-console-2.0.0/lib/action_dispatch/templates/rescues/template_error.html.erb within rescues/layout (72.0ms)

有没有办法摆脱这个错误?还是bug?

【问题讨论】:

  • 当我的 js 坏了时,我遇到了这种错误。我想问题是你添加了什么js?我非常怀疑这是一个错误。
  • 如果您认为 turbolinks 有问题,您可以在 Gemfile 中将其关闭(只需将其删除),然后您可以bundle update(我正在使用它,我可以告诉您我)我非常有信心它的工作)
  • 此时我只有 application.js 和land.js.coffee。我也怀疑这是一个错误。我不知道。
  • 它们里面有什么?尝试删除land.js,看看你是否得到了那个错误(我假设你没有对application.js做太多事情
  • @jcuenod 不,这两种方法都不起作用。

标签: ruby-on-rails ruby-on-rails-4 turbolinks


【解决方案1】:

我最近为这个问题找到了另一种解决方案。 gem 'coffee-script-source' in 1.9.0Windows 上有一些 Rails 问题。我在 Gemfile 中使用 gem 'coffee-script-source', '1.8.0' 恢复到以前的版本,这将解决您的问题。

解决此异常的另一种方法是将Node.js 安装到您的计算机上,安装并重新启动rails server 后错误应该会消失。确保在重新启动终端并重新运行服务器之前将 Node.js 添加到 PATH 中。

【讨论】:

  • 它是双向的。虽然,当coffee-script-source 降到 1.8.0 时,我可以放回 turbolinks。
  • 我遇到了同样的问题,这个解决方案效果很好。我也在一台 Windows 机器上。
  • 这个也解决了我在 Windows 10 电脑上的问题,非常感谢
  • 更换coffee版本遇到了另一个问题,但是安装node.js解决了这个问题。注意,安装后需要将节点添加到PATH,然后启动新的命令行并重新启动rails服务器
【解决方案2】:

我正在运行 Windows 10、Ruby 2.1.7p400 和 Rails 4.2.4。我无法安装 gem coffee-script-source '1.8.0',因为 gem 坚持使用 1.9.1.1 版本。我尝试将 ExecJS 更改为使用 UTF-8 编码并运行 cscript 而无需像 this 帖子中的 //U 开关,也没有任何运气。

我最终将 nodejs.exe 放在 Ruby\bin 文件夹中,问题得到解决。

【讨论】:

    【解决方案3】:

    啊,你好像不见了

    //= require turbolinks
    

    在你的 application.js 中

    请参阅 this 了解如何删除 turbolinks(如果您希望它运行,请确保一切就绪)。

    【讨论】:

    • @jcuenod in my application.js 您指定的代码可用,但没有解决我的问题
    猜你喜欢
    • 1970-01-01
    • 2012-10-18
    • 2021-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-04
    • 2020-04-01
    • 1970-01-01
    相关资源
    最近更新 更多