This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| gemfile追記 | |
| group :development, :test do | |
| gem "spring" | |
| gem 'spring-commands-rspec' | |
| end | |
| bundle install | |
| bundle exec spring binstub --all |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| なーんとなくDB作り直したいとき | |
| rake db:reset | |
| → rake db:drop | |
| → rake db:create | |
| → rake db:schema:load | |
| migrate追加したとき | |
| rake db:migrate | |
| migrate追加したタイミングでDB作り直したいとき なんとなくschema.rbを作り直しつつDB作り直したいとき |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- find_by -- | |
| User.find_by(id: 1) | |
| SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1 | |
| => #<User id: 1> | |
| User.find_by(id: 0) | |
| SELECT `users`.* FROM `users` WHERE `users`.`id` = 0 LIMIT 1 | |
| => nil #●見つからない場合はnil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Capybaraを使わない、RSpecのみで使えるものを気づいたらメモる | |
| describe User do | |
| describe "状況A" do | |
| before do | |
| user = User.new | |
| end | |
| describe "状況B (つまりはA-B)" do | |
| before { xxxxx } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # has_one = ひとつ持つ | |
| # has_many = いっぱい持つ | |
| # belongs_to = 所属する | |
| # ひとりの上司は複数の部下を持っています | |
| # 1 対 多 | |
| 上司 -> has_many -> 部下 | |
| 上司.部下s => [部下1, 部下2] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #paramsをそのまま引数に使うんじゃねえみたいな | |
| def update | |
| if @user.update_attributes(user_params) | |
| flash[:success] = "Profile updated" | |
| redirect_to @user | |
| else | |
| render 'edit' | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class User | |
| . | |
| . | |
| #クラス変数へのアクセサ | |
| cattr_accessor(:current_user) | |
| . | |
| . | |
| end | |
| class ApplicationController |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #servers, roles の設定箇所のナウい書き方はどんなだ? | |
| #こうして列挙するか | |
| server 'localhost', roles: [:app], user: 'moko', | |
| ssh_options: { | |
| keys: [File.expand_path('~/.ssh/id_rsa')] | |
| } | |
| server 'localhost', roles: [:db], user: 'moko', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rails new mokotest -d mysql --skip-bundle --skip-test-unit | |
| .gitignore 追記 | |
| config/database.yml | |
| config/secrets.yml | |
| Gemfile 修正 | |
| therubyracerのコメント外し |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| show variables like 'character_%'; | |
| status | |
| show create table [TABLE NAME]; | |
| 結局は、Ver5.6系ならデフォのまま使えるかなーと思ったらダメ | |
| サボらずに設定しろってこった | |
| [mysqld] | |
| character-set-server=utf8 | |
| collation-server=utf8_general_ci |
OlderNewer