【问题标题】:therubyracer or nodejs, which should I use?therubyracer 或 nodejs,我应该使用哪个?
【发布时间】:2013-01-27 13:35:10
【问题描述】:

我在新安装的 Ubuntu 12.10 上关注 ruby on rails getting started guide。我准备运行rake db:create,但出现以下错误:

rake 中止! 找不到 JavaScript 运行时。有关可用运行时列表,请参阅 https://github.com/sstephenson/execjs

我四处搜索,建议的解决方案(见下面的列表)是安装一些 therubyracer 或 nodejs,但他们没有解释原因。

在我开始安装之前,我想知道这些 JavaScript 运行时之间有什么区别,以及为什么我会选择其中一个?

更新:

我刚刚阅读了https://github.com/sstephenson/execjs(我知道我应该先阅读此内容,抱歉),在我看来 execjs 不是 JavaScript 运行时并且我已经拥有它......所以它取决于 therubyracer 和 nodejs .. . 请原谅我的无知,我已经修改了我的问题

除了 Intrepidd 的回答:

ruby on rails getting started guide 支持 Intrepidd 的回答。请参阅4.1 "Starting up the Web Server" 部分,其中写道:

Rails 在新的注释行中将 therubyracer gem 添加到 Gemfile 应用程序,如果需要,您可以取消注释。

对于那里的 Rails 新手(像我一样),GemFile 位于 Rails 应用程序的根文件夹中。在我的 GemFile 中取消注释该行后,我必须运行 bundle install 来安装 therubyracer gem。

【问题讨论】:

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


    【解决方案1】:

    您应该更喜欢 NodeJS 而不是 therubyracer,因为 NodeJS 具有内存效率,但它可能不那么容易安装,尽管在 Mac OS 上很容易,所以在 Ubuntu 上也很容易。

    【讨论】:

    • 您能否提供任何说明,或提供有关如何安装它的文章的链接?
    • 在 Mac 上,您可以使用 homebrew 安装一个简单的命令。 brew install node 就是这样,然后您可以通过在终端中运行命令 node 来验证这一点,然后您将不再需要 'gem "therubyracer"' 行,如果您在 ubtuntu 上部署,您可以使用 sudo apt-get install nodejs 安装在 heroku 和 rackspace 上使用节点。在 heroku 上,您不需要安装 node,因为它已为 rails 预装。
    • @Dean head do gorails.com/setup/ubuntu/14.10 获取有关如何安装 nodejs 的信息
    【解决方案2】:

    在 *NIX 系统上,您只需取消注释 gemfile 中的 gem "therubyracer" 就可以了,这是最简单的。

    【讨论】:

    • gem "therubyracer" 不在 GemFile 中...我想我应该添加它? (对不起我的最后一条评论,我误读了你的答案)......叹息,没关系发现它是这样的:#gem 'therubyracer', :platforms => :ruby
    • 好的,这样就成功了,干杯!所以 therubyracer 更容易,你能告诉我为什么 therubyracer 比 nodejs 更适合 Rails 开发,还是没有明确的答案?不要误会我的意思,“最简单”是一个很好的理由。
    • 我从不使用 node 作为 js 运行时,但我想这只是一个性能和实现问题。而且我不确定,但如果你想使用 node.js,除了安装我认为的 gem 之外,你必须手动安装它,但不确定。
    • 他们说therubyracertherubyracer-heroku 强烈反对,因为这些 gem 占用大量内存devcenter.heroku.com/articles/rails-asset-pipeline#therubyracer跨度>
    • 我不赞成你的回答,因为 Node.js 在大多数平台上安装起来相当简单,并且提供比 therubyracer 更好的性能。使用 therubyracer 比安装 Node.js 稍微容易一点,这并不是使用它的好理由。
    猜你喜欢
    • 2012-03-10
    • 2011-07-25
    • 1970-01-01
    • 2012-11-11
    • 1970-01-01
    • 2012-08-05
    • 2015-02-04
    • 2010-09-17
    • 1970-01-01
    相关资源
    最近更新 更多