Rails3.1, rails3.2でアプリケーションを実行すると以下のようなエラーが発生します。
> rails server
/usr/pkg/lib/ruby/gems/1.9.3/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime.
See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
from /usr/pkg/lib/ruby/gems/1.9.3/gems/execjs-1.4.0/lib/execjs.rb:5:in `<module:ExecJS>'
from /usr/pkg/lib/ruby/gems/1.9.3/gems/execjs-1.4.0/lib/execjs.rb:4:in `<top (required)>'
:
:
Gemfileのtherubyracerを有効にしてもlibv8がインストールできず動作しません。linuxなら動作します。
残念ながらlibv8は今(2013-1-30)のところnetbsdに対応していません。パッチをあててインストールする方法もあるようなのですが・・・ちょっと面倒です。
でも、development(またはtest)環境では動作しませんが、production環境では動作します。
> rails server -e production
=> Booting WEBrick
=> Rails 3.2.11 application starting in production on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
なので、Gemfileの中のgroup :assets doの括りをコメントアウトします。開発環境だけに使用するだけなので必要ありません。(コメントにもassets(開発とテスト環境)だけで使用すると書いてあります) これでnetbsdでも正常に動作します!
# Gems used only for assets and not required
# in production environments by default.
# group :assets do
# gem 'sass-rails', '~> 3.2.3'
# gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
# gem 'uglifier', '>= 1.0.3'
# end
:
:
または、コメントアウトにせずに、以下のようにしても全く同じです。
> bundle install --without assets
assetsの除外(without)設定は.bundle/configに保管されます。ここを消せば元にもどります。
BUNDLE_WITHOUT: assets
ちなみに、groupの :assets はどこから来ているのか調べると、./config/application.rbにありました。
require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
:
:
rails 4.0 になると Gemfileの中のassetsで囲んだ箇所がありませんが、 coffee-railsとuglifierをコメントアウトすれば動きます。
# Use Uglifier as compressor for JavaScript assets
#gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
#gem 'coffee-rails', '~> 4.0.0'