ぞえの技術めも

Ruby on Rails勉強中

【11日目】【1日20分のRailsチュートリアル】sample_appアプリケーションのセットアップ

Ruby on Railsチュートリアル(第3版)

今日は「第3章 ほぼ静的なページの作成」から。

3章からTwitter的なWebアプリケーションの作成に着手。

3.1 セットアップ

3回目なRailsプロジェクトの生成。
今回は「sample_app」という名前で。

$ rails _4.2.2_ new sample_app
$ cd sample_app/

Gemfileを更新。

source 'https://rubygems.org'

gem 'rails',        '4.2.2'
gem 'sass-rails',   '5.0.2'
gem 'uglifier',     '2.5.3'
gem 'coffee-rails', '4.1.0'
gem 'jquery-rails', '4.0.3'
gem 'turbolinks',   '2.3.0'
gem 'jbuilder',     '2.2.3'
gem 'sdoc',         '0.4.0', group: :doc

group :development, :test do
  gem 'sqlite3',     '1.3.9'
  gem 'byebug',      '3.4.0'
  gem 'web-console', '2.0.0.beta3'
  gem 'spring',      '1.1.3'
end

group :test do
  gem 'minitest-reporters', '1.0.5'
  gem 'mini_backtrace',     '0.1.3'
  gem 'guard-minitest',     '2.3.1'
end

group :production do
  gem 'pg',             '0.17.1'
  gem 'rails_12factor', '0.0.2'
end

bundle installを実施。

$ bundle install --without production

gemのバージョンは合ってるような気もするけど一応コマンド打っておく。

$ bundle update

ここまでできたらGitリポジトリの初期化。

$ git init
$ git add -A
$ git commit -m "Initialize repository"

READMEの修正。

$ git mv README.rdoc README.md

README.md

# Ruby on Railsチュートリアル: サンプルアプリケーション

これは以下に基づいたサンプル・アプリケーションです
[*Ruby on Railsチュートリアル:
実例を使ってRailsを学ぼう*](http://railstutorial.jp/)
[Michael Hartl](http://www.michaelhartl.com/)著

READMEの修正をコミット。

$ git commit -am "Improve the README"

今までの変更をBitBucketにpush。
BitBucketにリポジトリ作成して

f:id:kt_zoe:20160722124039p:plain

$ git remote add origin git@bitbucket.org:<username>/sample_app.git
$ git push -u origin --all

pushできた。

f:id:kt_zoe:20160722124100p:plain

お次はHello, World!。

app/controllers/application_controller.rb

  def hello
    render text: "hello, world!"
  end

config/routes.rb

  root 'application#hello'

念のためローカルで動作確認。

$ cd sample_app/
$ rails server -b $IP -p $PORT

f:id:kt_zoe:20160722124143p:plain

問題なし。

GitにコミットしてHerokuにもpush。

$ git commit -am "Add hello"
$ heroku create
Creating app... done, ⬢ infinite-depths-40805
https://infinite-depths-40805.herokuapp.com/ | https://git.heroku.com/infinite-depths-40805.git
$ git push heroku master

Herokuの本番環境でも動作見れたら今日はここまで。
準備完了。

今日の作業時間は【25分】

次は「3.2 静的ページ」から。