Creating an admin user in Devise on Rails beta 3

前端 未结 6 1231
梦谈多话
梦谈多话 2020-12-22 16:35

Ok, I\'m probably going to feel quite dumb when someone answers this one with a simple thing that I\'m missing but... here goes:

I\'ve got a brand new app on rails 3

6条回答
  •  -上瘾入骨i
    2020-12-22 17:13

    What you are really trying to do is create seed data. A more standard way to do this would be to add your seed users (and roles, if you are storing them) to db/seeds.rb

    For exmaple in db/seeds.rb:

    roles = Role.create([{name: 'super_admin'}, {name: 'staff'}, {name:'customer'}])
    users = User.create([{email: 'super@test.com', first_name: 'super', last_name: 'admin', password: '@dmin123', password_confirmation: '@dmin123', role: roles[0]}])
    

    Then run:

    rake db:seed
    

提交回复
热议问题