LoginSignup
0
0

More than 3 years have passed since last update.

current_userメソッド

deviseでログイン機能を実装すると使えるようになるメソッド。
idが1のレコードの場合、User.find(1)と同じ意味を持ちます。
current_user.nameなどで値を取得できます。

ルーティングでユーザーごとに異なるページを表示するには普通とは違う記述方法を使います。

routes.rb
get 'users/:id' => 'users#show'

whereメソッド
Active Recordの1つ
モデル.where(条件)で引数にとった条件に一致したレコードのインスタンスを配列型で取得できます。
条件を連続で記述すれば複数の条件にあったレコードを取得できます。

Sample.where('id < 3').where('user_id: 1')

アソシエーション

モデル間の関係を定義することで、モデルを跨いだデータの呼び出しが簡単になります。

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