Ruby2/Rails4でHello, world!を表示してみる
CentOSにRuby2.1とRails4.1をインストールしてみる
の続き
Ruby2.1とRails4.1でHello, world!を表示してみる。
サンプルのRailsアプリを作成する。
$ rails new sample
$ cd sample
下記の箇所のコメントを外し、インストールする。
$ vi Gemfile ・・・ gem 'therubyracer', platforms: :ruby ←コメントを外す ・・・
$ bundle install
コントローラを作成する。
$ rails generate controller sample
$ vi app/controllers/sample_controller.rb
class SampleController < ApplicationController
def index
end
end
ルートを設定する。
$ vi config/routes.rb ・・・ # root 'welcome#index' root 'sample#index' ←追加 ・・・
ビューを作成する。
$ vi app/views/sample/index.html.erb <h1>Hello, world!</h1>
サーバーを起動して、ブラウザからアクセスすると、
$ rails server