![](/img/trans.png)
[英]How to setup 2 aliased has_and_belong_to_many relationships with one class?
[英]What is the best way to check if the “Admin” Group is in the user groups (using has_and_belong_to_many relationships) in Rails 3?
我只想检查“ Admin”组是否在用户组中。 用户和组模型具有has_and_belong_to_many关系。
我的系统可以在开发人员模式下与Rails正常工作,但是当我尝试传递到生产环境时,“游戏”控制器中的这一行不起作用:
if current_user.groups.where(:name => "Admin") != []
ActiveRecord::StatementInvalid (Mysql2::Error: Table 'db_production.groups' doesn't exist: SHOW FIELDS FROM `groups`)
此外,相同的查询在rails控制台中也可以正常工作:
irb(main):001:0> User.find(1).groups.where(:name =>
User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`i
Group Load (0.4ms) SELECT `groups`.* FROM `groups` INNER JOIN `groups_users` ON `groups`.`id` = `groups_users`.`group_id` WHERE `groups_users`.`user_id` = 1 AND `groups`.`name` = 'Admin'
=> false
该服务器具有Rails 3.2.0,并在Apache上使用Phusion Passenger版本3.0.11。 我使用设备gem进行用户管理。
从错误消息中清除groups
表在db_production
数据库中不存在。
Mysql2::Error: Table 'db_production.groups doesn't exist
您的迁移可能在生产服务器中失败了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.