I’m using Rails 4.2.5 with the “omniauth-google-oauth2” gem. In my application, the only way users will be able to sign in is through their Google or Facebook logins. What I would like is to pre-populate my application with an initial user, me (email = ‘davea@gmail.com”), with the admin role. It would be nice to do this programmatically so that when I roll this out to other environments I can use the same code.
My roles table (through db/seeds.rb) has the roles
Admin
User
and my app/model/user.rb file has
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.name
user.oauth_token = auth.credentials.token
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
user.save!
end
end
I’m not sure how to do what I want, however, and so would value some counsel.