Fresh Rails 3.1 安装失败...未初始化常量 JSON::ParserError

发布于 2024-12-05 09:32:21 字数 916 浏览 1 评论 0 原文

我正在使用 RVM 并多次安装了 Rails 3.1.0,但一旦开始使用它,我就会一遍又一遍地遇到相同的错误。

从全新安装的 Rails 3.1.0 中,我执行以下操作:

rails new fishapp

cd fishapp

bundle install

rails g scaffold Fish name:string

bundle exec rake db:migrate

但每次我转到 http://localhost:3000/fish 我得到:

Showing /Users/me/code/rails31/fishapp/app/views/layouts/application.html.erb where line #6 raised:

uninitialized constant JSON::ParserError
  (in /Users/me/code/rails31/fishapp/app/assets/javascripts/fish.js.coffee)

Extracted source (around line #6):

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

我一定是在尝试安装 Rails 时损坏了某些东西或其他东西,因为我不明白为什么全新安装会失败。有什么想法吗?

I am using RVM and have installed rails 3.1.0 multiple times but once I begin using it I get the same error over and over again.

From a fresh install of rails 3.1.0 I do the following:

rails new fishapp

cd fishapp

bundle install

rails g scaffold Fish name:string

bundle exec rake db:migrate

But each time I go to http://localhost:3000/fish I get:

Showing /Users/me/code/rails31/fishapp/app/views/layouts/application.html.erb where line #6 raised:

uninitialized constant JSON::ParserError
  (in /Users/me/code/rails31/fishapp/app/assets/javascripts/fish.js.coffee)

Extracted source (around line #6):

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

I must have broke something trying to get rails installed or something as I don't otherwise understand why it would fail of a fresh install. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吃→可爱长大的 2024-12-12 09:32:21

最初我只是注释掉了第 6 行(这样我就可以继续工作)。

<%#= javascript_include_tag "application" %>

最终我需要 javascript,所以我不得不回到这个问题。我将上面的行注释掉,并在其正下方硬编码了这一行:

<script src="/assets/application.js" type="text/javascript"></script>

页面加载正常,所以我查看了页面的源代码,然后查看

http://0.0.0.0:3000/assets/application.js

...只是发现了类似的错误:

throw Error("NameError: uninitialized constant JSON::ParserError
(in /Users/me/Dev/fishapp/app/assets/javascripts/products.js.coffee)")

所以我决定加载一个Rails 控制台,看看我是否可以加载 JSON gem,但 iconv 出现错误:

ruby-1.9.2-p290 :001 > require 'json'
LoadError: no such file to load -- iconv

同时加载生成的 Rails gem:

ruby-1.9.2-p290 :004 > require 'rails'
 => false 

所以我四处搜索并发现了这个:

http://beginrescueend.com/packages/iconv/

按照这些说明操作,您的问题将会得到解决!根据记录,这些说明是:

rvm pkg install iconv
rvm remove 1.9.2
rvm install 1.9.2 --with-iconv-dir=$rvm_path/usr

我将保留我所采取的步骤,以防其他人在 Google 上搜索类似错误。

Initially I simply commented out line #6 (just so I could keep working).

<%#= javascript_include_tag "application" %>

Eventually I needed javascript, so I had to return to this issue. I kept the line above commented out, and just hard-coded this one immediately below it:

<script src="/assets/application.js" type="text/javascript"></script>

The page loaded fine, so I viewed the page's source, and looked at

http://0.0.0.0:3000/assets/application.js

... only to find a similar error:

throw Error("NameError: uninitialized constant JSON::ParserError
(in /Users/me/Dev/fishapp/app/assets/javascripts/products.js.coffee)")

So I decided to load a rails console and see if I could load the JSON gem, but got an error with iconv:

ruby-1.9.2-p290 :001 > require 'json'
LoadError: no such file to load -- iconv

Meanwhile loading the rails gem produced:

ruby-1.9.2-p290 :004 > require 'rails'
 => false 

So I searched around and found this:

http://beginrescueend.com/packages/iconv/

Follow those instructions, and your problem will be resolved! For the record, those instructions are:

rvm pkg install iconv
rvm remove 1.9.2
rvm install 1.9.2 --with-iconv-dir=$rvm_path/usr

I'm leaving the steps I took in case others search Google for similar errors.

如何视而不见 2024-12-12 09:32:21

您可以尝试执行其中一些操作,看看是否有帮助,

  • 检查您的 Gemfile 以确保那里有 gem Coffee 脚本
  • 检查您的 Gemfile.lock 文件以确保满足所有依赖项。您可能应该在 activesupport 下有 multi_json
  • 您还可以尝试在安装 Rails 3.1 之前执行 rvm get head 并进行捆绑安装,看看是否有帮助。

You could try to do some of these to see if it helps,

  • Check your Gemfile to ensure you have gem coffee script there.
  • Check your Gemfile.lock file to make sure all your dependencies are satisfied. You should probably have multi_json under activesupport.
  • You could also try to doing an rvm get head before installing rails 3.1 and doing your bundle install to see if that helps.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文