在 Rails 中查询 Devise users 表
我刚刚设置了 Devise auth 库,但我对如何查询它感到困惑。
例如,之前当我制作自己的 users 表时,我制作了这个 user.rb 文件,
class User < ActiveRecord::Base
set_primary_key:uid
end
并且我能够通过 uid 进行查询,如下所示:
@User = User.find(1)
print @User
现在 Devise 添加了许多列,users.rb 文件如下所示
class Users < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:first_name, :last_name, :organization_name
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
end
:查询该表的代码不起作用,我不确定如何查询它。
另外,我不确定我是否应该做这样的事情
rails generate devise User
我在这里哪里出错了?
I just set up the Devise auth library and I am confused about how it is meant to be queried.
For example, before when I made my own users table, I made this user.rb file
class User < ActiveRecord::Base
set_primary_key:uid
end
And I was able to query by uid like this:
@User = User.find(1)
print @User
Now that Devise added a number of columns and the users.rb file looks like this:
class Users < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:first_name, :last_name, :organization_name
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
end
The above code to query this table does not work and I am not sure how it is meant to be queried.
Also, I am not sure if I should do something like this
rails generate devise User
Where am I going wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为覆盖 Rails 默认主键不是一个好习惯,也许您可以尝试通过以下方式查找用户:
I don't think it's a good practice to override the Rails default primary keys, perhaps you could try finding your users the following way instead: