Ruby on Rails Tuesday, July 11, 2017

On Tue, Jul 11, 2017 at 6:33 AM, Ralph Shnelvar <> wrote:

> I want to make sure the first user gets to set it's role attribute to enum
> :admin as the default when the record is created and all other users are
> enum :user.
> Of course a billion users is ridiculous. I'm just trying to understand what
> the, uh, best way to see if a Postgres table is empty without actually
> having to load it.

Assuming the table is "users" and User is an ActiveRecord model,
(User.count == 0)
should work.

However, doing that for every subsequent user creation seems like
a bit of a waste. I would just use the db/seeds.rb file to create that
first admin user and be done with it :-)

Hassan Schroeder ------------------------
twitter: @hassan
Consulting Availability : Silicon Valley or remote

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment