5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

定義してないのになぜか使える activated? admin? メソッド Ruby on Rails チュートリアル

Posted at

こんなメソッド定義してないぞ?と思いきや、
Railsでは真偽値をとるカラムであれば、モデル.カラム名?で真偽値を取得できるらしいです。

user_model_account_activation.png

>> user = User.first
  User Load (0.1ms)  SELECT  "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT ?  [["LIMIT", 1]]
=> #<User id: 1, name: "Example User", email: "example@railstutorial.org", created_at: "2020-03-15 10:30:06", updated_at: "2020-03-15 10:30:06", password_digest: "$2a$10$XvC6suqKbRRIHIm8nQOyjeQcKJixPXdm1b331TQJ7y5...", remember_digest: nil, admin: true, activation_digest: "$2a$10$5/9pDzSQIJdzpaAbFCJZO.qptq0BYtnH.Q/sBwP5epB...", activated: true, activated_at: "2020-03-15 10:30:06">

user.admin?
=>true

user.activate?
=true
5
4
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
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?