LoginSignup
5
5

More than 5 years have passed since last update.

Ruby on Rails チュートリアル メモ抜粋

Last updated at Posted at 2014-04-02

■railsプロジェクト生成時
①プロジェクト生成
$ cd rails_projects
$ rails new app001
$ cd app001

②Gemfile更新

③バンドル設定
$ bundle install --without production
$ bundle update
$ bundle install

④GIT初期化
$ git init
$ git add .
$ git commit -m "Initial commit"

⑤githubプッシュ
$ git remote add origin https://github.com//app001.git
$ git push -u origin master

■DBテーブル生成
$ rails generate scaffold User name:string email:string
$ bundle exec rake db:migrate

■静的ページの作成
$ rails generate controller StaticPages home help --no-test-framework
(コントローラ名はキャメルで)

■トピックブランチの作成
$ git checkout -b static-pages

■マスターブランチへ移動してトピックブランチをマージ
$ git checkout master
$ git merge static-pages

■コントローラ、モデルの削除
$ rails generate controller FooBars baz quux
$ rails destroy controller FooBars baz quux

$ rails generate model Foo bar:string baz:integer
$ rails destroy model Foo

■マイグレーションを元に戻す

$ rake db:migrate

以下のコマンドで1つ前の状態に戻すことができます。

$ rake db:rollback

最初の状態に戻したい場合は、以下のコマンドを使います。

$ rake db:migrate VERSION=0

■git push heroku master で失敗する

Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

↑のようなエラーが出る場合は、sshの設定がおかしい可能性大。
①~/.ssh に「id_rsa」と「id_rsa.pub」があるかを確認して、もし無ければ作る
 1. 「ssh-keygen -t rsa」をターミナルで実行
 2. 「Enter file in which to save the key (/Users/username/.ssh/id_rsa): 」と聞かれるのでそのままEnter
 3. 「Enter passphrase (empty for no passphrase): 」と聞かれるのでとりあえず何か打ち込んでおく(あとから聞かれるので覚えておく)。
 4. id_rsaとid_rsa.pubが生成されるので、「heroku keys:add」で公開鍵を登録。先ほどのパスフレーズを入力。
 5. git push heroku masterを実行

5
5
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
5
5