Advertisement
Guest User

Untitled

a guest
Jun 12th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. This is quite a 'classic' problem and the immediate thought ("just do it mySQL") doesn't work here because of the need to have the rails piece that encodes a password that is entered.
  2.  
  3. So you need to actually use rails, something like this (this should all be happening in your local development environment which is the default when working locally):
  4.  
  5. You need to create a user.
  6.  
  7. Try this:
  8.  
  9. ```bash
  10. cd the_root_of_the_project
  11. script/rails console
  12. ```
  13.  
  14. ```ruby
  15. > User.create(:username => 'admin',
  16. :password => 'abc123',
  17. :password_confirmation => 'abc123')
  18. # Add other fields, such as first_name, last_name, etc.
  19. # as required by the user model validators.
  20. # Perhaps :admin => true
  21. ```
  22. This assumes a few things (so change as required) such as an authentication system such as authLogic or devise, attribute and field names, etc, but you should be able to adjust to your needs. You can determine what these are by looking at a few things, specifically the database migration files in db/migrate, the model validations in `user/model/user`, any existing "seeds" filew for users in `db/seeds.rb` and the authentication system hooks.
  23.  
  24. As to 'where' to do this - obviously the console works but you might also want to use the seeds file for this. Whatever 'create' command you use in the console can be placed in here, then run with `rake db:seed`. The downside is that if you check this file into source control it's less secure. The seeds file is really useful for other tasks such as creating reference tables, initial categories, etc.
  25.  
  26. If you don't have the database actually created at all yet, you'll need to be aware of and use these tasks:
  27.  
  28. ```bash
  29. rake db:create
  30. # as it sounds, creates a database (but no application tables or columns),
  31. # using the config/database.yml file for the connection info.
  32.  
  33. rake db:migrate
  34.  
  35. # Creates tables and columns using the db/migrate/ files.
  36.  
  37. rake db:seed
  38.  
  39. # Runs commands in db/seeds.rb to create initial records for the application.
  40. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement