- Docker内に入るコマンド
$ docker exec -it xtreme_server bash
- Devise Token Auth認証について
- controllerの生成
bundle exec rails g controller <...>
- Modelの生成
bundle exec rails g mdoel <...>
- migrationファイルの生成
bundle exec rails g migration <...>
- dbをmigrate
bundle exec rails db:migrate
- migrateなどで失敗した時の対処法
1つのテーブルに1つのmigrationファイルにすること! (無駄にファイル数を増やしたくない)
bundle exec rails db:migrate:reset
- RSpec実行
bundle exec rspec <ディレクトリ>
- Rubocopの実行(自動修正モード)
bundle exec rubocop -a
app/
┣━ assets/
┣━ channels/
┣━ controllers/
┣━ decorators/ gem `draper`を使用
┣━ helpers/ 未使用
┣━ jobs/ 今の所使う予定なし
┣━ mailers/ action mailerとして使う可能性あり
┣━ models/ fatモデルにならないように気をつける
┣━ usecases/ service層 controllerやmodelのdelegateモジュール
┣━ queries/ controllerでの処理のフィルタリングに使用
┗━ views/ json.jbuilderで書く。
認証は DeviseTokenAuthを用いて
api/auth/registrations_controller.rb
が DeviseTokenAuth::RegistrationsController
を継承!
createsメソッド
はDeviseTokenAuth::RegistrationsController
を用いて、sign_up_params
はオーバーライドしている。
app/controllers/application_controller
がDeviseTokenAuth::Concerns::SetUserByToken
モジュールをincludeしているため、どのcontrollerでもいちいちaccess-tokenなどを定義する必要なし。
csrf対策
はまだ未定。今後に導入。
devise_token_authは、headerに"access-token"
、"client"
、uid
を乗せてリクエスト送る。
{
"access-token": "lhG-DTB64dyOlv1e-6BAiQ",
"client": "RqCpylnDWcDUQVntAbpyDw",
"uid": "[email protected]"
}
使えるメソッド
1. api_user_signed_in?
2. before_action :authenticate_api_user!
3. current_api_user
{
"name": "hogehoge1",
"email": "[email protected]",
"password": "hogehoge1",
"password_confirmation": "hogehoge1",
"reset_password_token": "hoegehoge1",
"uid": "[email protected]"
}
mongodbを使用していないrspec
$ bin/rspec-test-queue.rb --exclude-pattern "spec/mongo/**/*_spec.rb" spec/
$ bundle exec rspec spec/mongo/.