LoginSignup
0
0

More than 5 years have passed since last update.

Rails勉強メモ

Posted at

resourcesメソッドのオプション

resources :users, only: [:index, :new]

指定したルーティングを設定

resources :users, :except [:index, :new]

指定された物以外のルーティングを設定

resources :users, controller: 'hoge'

コントローラの変更

resources :users, path: 'hoge'

URLパスの変更

if @user.save

saveメソッドはバリデーションに失敗するとfalseを返す。

expect { patch :update, id: user.id, user: params_hash }.not_to change { user.hashed_password.to_s }

Rspecのテストでchangeマッチャーはターゲット(BCrypt::Passwordオブジェクト)の==メソッドで比較をするので、to_sで文字列に変換して合わせる。

    create_table :user_events do |t|
      t.references :user, null: false
    end

TableDefinitionオブジェクト(t)のreferencesメソッドは指定された名前の末尾に_idを追加して整数型のカラムを定義する(:user_id)。

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