【问题标题】:Javascript doesn't work for javascrip_inlcue-tag Rails 3.2.2Javascript 不适用于 javascrip_inlcue-tag Rails 3.2.2
【发布时间】:2012-04-08 09:57:18
【问题描述】:

我正在关注 Michael Hartl's book Ruby on Rails 3 Tutorail 中的 demo_app。该演示是一个简单的脚手架用户名:字符串电子邮件:字符串

我的 application.html.erb 文件出现错误:

Errno::EINVAL in Users#index 
Showing ~/demo_app/app/views/layouts/application.html.erb where line #6 raised: 
Invalid argument - cscript //E:jscript //Nologo //U /tmp/execjs20120323-4388-1an85xw-0.js 2>&1
(in ~/demo_app/app/assets/javascripts/users.js.coffee)

3: <head>
4:   <title>DemoApp</title>
5:   <%= stylesheet_link_tag    "application", :media => "all" %>
6:   <%= javascript_include_tag "application" %>
7:   <%= csrf_meta_tags %>
8: </head>
9: <body>

如果我将第 6 行更改为:

<%= javascript_include_tag "default" %>

该程序将完美运行,但它不允许我删除用户(可能是因为它没有运行 javascript)。

环境信息:

$ ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [i386-cygwin]

$ rails -v
Rails 3.2.2

~\demo_app\app\assets\javascripts\users.js.coffee 的内容:

# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/

~\demo_app\app\assets\javascripts\application.js 的内容

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require_tree .

【问题讨论】:

  • 发布您的users.js.coffee 文件。
  • 能否把app/assets/javascripts/users.js.coffee的内容贴出来。还要确保您遵循 Rails 3.2 的本书版本 - ruby.railstutorial.org/ruby-on-rails-tutorial-book?version=3.2
  • john,确认我正在关注 version=3.2。
  • 上面发布的 user.js.coffee 的内容。
  • 请发布您的 application.js 和您的 app/assets/javascript 文件夹中的文件。

标签: javascript ruby-on-rails ruby-on-rails-3


【解决方案1】:

尝试取消注释 gem 'therubyracer' 并运行 bundle,并且最好使用最新的 ruby​​ 稳定版本

【讨论】:

  • 我删除了对 therubyracer 的评论,并且 bundle install 遇到了 libv8 gem 的问题。错误:“安装 libv8 (3.3.10.4) 时出错,Bundler 无法继续。在捆绑之前确保gem install libv8 -v '3.3.10.4' 成功。”
  • 卸载 libv8: git clone git@github.com:fractaloop/libv8 cd libv8 git submodule update --init bundle install bundle exec rake compile
  • 说,即使我的程序运行正常,我还是应该按照你的建议取消对 gem therubyracer 的注释并卸载 libv8 吗?
  • ooop,我以为你安装 libv8 时遇到问题,如果安装成功,那么你可以跳过上一步,所以 Users#index 中的 Errno::EINVAL 已经消失了?
  • 是的,Errno: EINVAL 已消失。
【解决方案2】:

我四处寻找其他讨论 gem therubyracer 的问题。我找到了一个答案,它暗示了 Said Kaldybaev 在这里提出的建议。那对我不起作用。但是还有另一个建议g删除代码

//= require_tree . 

来自 app/assets/javascripts/application.js 文件。

删除该代码使应用程序工作(包括销毁功能)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-14
    • 2013-02-20
    • 2012-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-11
    相关资源
    最近更新 更多