0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rails チュートリアル 第1章 まとめ

Last updated at Posted at 2019-10-18

versionを指定して、railsをインストール

gem install rails -v 5.1.6

アプリケーションの作成

rails _5.1.6_ new hello_app

アプリケーションに必要なgemをインストール
Gemfileをチュートリアル用に書き換える

bundle install
bundle update

rails serverを別タブで開く
cdでenvironmentからhello_appに移る
previewから開く

rails s

Applicationコントローラにhelloを追加する

def hello
    render html: "Hello world"
 end

ルーティングを追加

root 'application#hello'

MVC
ルーティングの役割
ブラウザから送られてくるURLをapplicationコントローラのhelloアクションに振り分ける
アクションの役割
コントローラ名とアクション名からviewを探し出し、呼び出す
(今回ならapps/views/application/hello.html.erb)
ビューの役割
ビューに書き込んだ内容がブラウザに表示される

Git
Gitの役割
セーブポイントを作ること
リポジトリ(保管場所)の初期化

git init

リポジトリに作業したファイルを追加

git add -A

待機用リポジトリ、色で状態を示す

git status

リポジトリに変更を反映

git commit -m "~~~~"

コミットの履歴を確認

git log

branchの確認

git branch

試行錯誤のため別のbranchで作業したい

git checkout -b "~~~"

作業し終わって、masterに組み込みたい時には

git add -A
git commit -m "~~~"
git checkout master
git merge (try branch)

Heroku
Heroku用にGemfileを変更する(install --without production,update)
Herokuインストール用のコマンド

source <(curl -sL https://cdn.learnenough.com/heroku_install)

herokuへのログインとログイン状態の保持

heroku login --interactive
heroku keys:add

herokuにアプリケーションの作成

heroku create

デプロイした画面へのショートカットを作成

git remote -v 

gitを使ってherokuにデプロイ

git push heroku master

urlからopenでheroku用のページを開くことができる

urlを変えたいなら

heroku rename ~~~
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?