Ruby on Rails簡単に触ってみた
Railsの構築準備簡単ですなぁ…CakePHPでアプリ書き始めたときもめんどくさがらずにbake使えばよかったかも[みくったー]
— ゆうなんとか@8/31きょうとさん (@yuu_hara) 8月 28, 2012
めんどくさいことは直接しなくていいのが楽ですね。
なお、環境とかは以下のとおりです。
アプリを構築したいところにディレクトリを移動したあと以下のコマンドを打ちます。
$ rails new <アプリケーション名> (中略) Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
最後のほうでこんな感じのメッセージが出れば最低限の準備は完了のはずです。ちなみに今回はPostgreSQLを使いたかったので
$ rails new <アプリケーション名> -d postgresql
とオプションをつけてやりました。
無事にコマンドの実行が終わると、アプリケーション名と同じディレクトリが出来上がっているので、そちらに移動します。そこでひとまず起動させてみると*1*2…
$ rails server /(*´ω`*)/.gem/ruby/1.9.1/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 /(*´ω`*)/.gem/ruby/1.9.1/gems/execjs-1.4.0/lib/execjs.rb:5:in `<module:ExecJS>' from /(*´ω`*)/.gem/ruby/1.9.1/gems/execjs-1.4.0/lib/execjs.rb:4:in `<top (required)>' from /usr/local/share/gems/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `require' from /usr/local/share/gems/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `<top (required)>' from /usr/local/share/gems/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `require' from /usr/local/share/gems/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `<top (required)>' from /(*´ω`*)/.gem/ruby/1.9.1/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `require' from /(*´ω`*)/.gem/ruby/1.9.1/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `<top (required)>' from /usr/local/share/gems/gems/bundler-1.1.5/lib/bundler/runtime.rb:68:in `require' from /usr/local/share/gems/gems/bundler-1.1.5/lib/bundler/runtime.rb:68:in `block (2 levels) in require' from /usr/local/share/gems/gems/bundler-1.1.5/lib/bundler/runtime.rb:66:in `each' from /usr/local/share/gems/gems/bundler-1.1.5/lib/bundler/runtime.rb:66:in `block in require' from /usr/local/share/gems/gems/bundler-1.1.5/lib/bundler/runtime.rb:55:in `each' from /usr/local/share/gems/gems/bundler-1.1.5/lib/bundler/runtime.rb:55:in `require' from /usr/local/share/gems/gems/bundler-1.1.5/lib/bundler.rb:119:in `require' from /(*´ω`*)/<アプリケーション名>/config/application.rb:7:in `<top (required)>' from /usr/local/share/gems/gems/railties-3.2.8/lib/rails/commands.rb:53:in `require' from /usr/local/share/gems/gems/railties-3.2.8/lib/rails/commands.rb:53:in `block in <top (required)>' from /usr/local/share/gems/gems/railties-3.2.8/lib/rails/commands.rb:50:in `tap' from /usr/local/share/gems/gems/railties-3.2.8/lib/rails/commands.rb:50:in `<top (required)>' from script/rails:6:in `require' from script/rails:6:in `<main>'
なんかものすごくおられてしまいました。それにしても(*´ω`*)←これかわいいですよね
ここのGitHubのIssueやここのブログの記事によると、どうやら「execjs」と「therubyracer」というgemを追加したらいいらしいということがわかったのでよっそいします。「よっそいする」って言い方もなんかかわいいですよね冒頭のコマンドでできたディレクトリの直下に「Gemfile」というファイルがあるので、その最後に
gem 'execjs' gem 'therubyracer'
と追加して保存したあと、
$ bundle install
で足りないgemをよそいます。ちなみにこれを忘れてしまったときは
$ rails server Could not find gem 'therubyracer (>= 0) ruby' in the gems available on this machine. Run `bundle install` to install missing gems.
と怒られるので上のメッセージで言われたとおりbundle installしましょう。
では改めて…
$ rails server => Booting WEBrick => Rails 3.2.8 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2012-08-29 17:55:31] INFO WEBrick 1.3.1 [2012-08-29 17:55:31] INFO ruby 1.9.3 (2012-04-20) [x86_64-linux] [2012-08-29 17:55:31] INFO WEBrick::HTTPServer#start: pid=23689 port=3000 [2012-08-29 17:55:41] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
こういうメッセージが出たら、http://localhost:3000 を見てみましょう。
うごいたあああああああああああああああああああああああああああああああああああ
というわけネタ切れになると困るので今回はここまで。
参考にさせていただいたのはこちら。