DrY*_*Yap 4 database authentication ruby-on-rails authlogic devise
我有一个Ruby on Rails应用程序,我是从Git repo克隆的.它需要登录才能执行任何操作,例如注册新用户.目前没有注册用户,所以我认为自己完全被锁定了
我知道用户存储在一个被调用的表中,users但底层数据库是MySQL,我不知道如何访问Ruby on Rails应用程序的数据库.
有谁知道如何添加用户?
Mic*_*ant 10
这是一个非常"经典"的问题,直接思考("只做它mySQL")在这里不起作用,因为需要有一个编码输入密码的rails片段.
所以你需要实际使用rails,就像这样(这应该在本地开发环境中发生,这是本地工作时的默认设置):
您需要创建一个用户.
试试这个:
cd the_root_of_the_project
script/rails console
> User.create(:username => 'admin',
:password => 'abc123',
:password_confirmation => 'abc123')
# Add other fields, such as first_name, last_name, etc.
# as required by the user model validators.
# Perhaps :admin => true
Run Code Online (Sandbox Code Playgroud)
这假定了一些事情(根据需要进行更改),例如身份验证系统(如authLogic或设计,属性和字段名称等),但您应该能够根据自己的需要进行调整.您可以通过查看一些内容来确定这些内容,特别是db/migrate中的数据库迁移文件,user/model/user中的模型验证,db/seeds.rb中用户的任何现有"种子"文件以及身份验证系统挂钩.
关于"在哪里"这样做 - 显然控制台可以工作,但你可能也想使用种子文件.无论你在控制台中使用什么'create'命令都可以放在这里,然后运行rake db:seed.缺点是,如果您将此文件检入源代码管理,则其安全性较低.种子文件是用于其它任务真正有用的,例如,创建参考表,初始类别等等
如果您还没有实际创建数据库,则需要了解并使用这些任务:
rake db:create
# as it sounds, creates a database (but no application tables or columns),
# using the config/database.yml file for the connection info.
rake db:migrate
# Creates tables and columns using the db/migrate/ files.
rake db:seed
# Runs commands in db/seeds.rb to create initial records for the application.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3409 次 |
| 最近记录: |