每当数据库干净,没有表时(通常在测试中以及设置要部署到的新服务器时),许多rake任务(如assets:precompile)都会因此错误而失败:
rake aborted!
PG::Error: ERROR: relation "users" does not exist
LINE 4: WHERE a.attrelid = '"users"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"users"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
任何想法为什么以及如何解决它?
如果我使用trace运行它,我可以看到来自staffer.rb:103的错误,其中包含:
scope :visible, where(:deleted => false)
如果我发表评论,至少资产:预编译工作。
似乎整个事情都是由active_admin触发的,admin / users.rb的第一行看起来像:
# encoding: UTF-8
#
ActiveAdmin.register User do
menu :priority => 2
filter :id
filter :rid
filter :tenant
filter :type, :as => :check_boxes, :collection => %w{Manager Staffer}
filter :state, :as => :check_boxes, :collection => Staffer::STATES
filter :email
filter :first_name
filter :last_name
整个错误如下:
1.9.3-p194@projectx root@b1:/var/nginx/projectx/releases/20120710151049# bundle exec rake RAILS_ENV=staging RAILS_GROUPS=assets assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
Resolved collector.newrelic.com to 204.93.223.153
rake aborted!
PG::Error: ERROR: relation "users" does not exist
LINE 4: WHERE a.attrelid = '"users"'::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = '"users"'::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:1151:in `async_exec'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:1151:in `exec_no_cache'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:664:in `block in exec_query'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:663:in `exec_query'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:1276:in `column_definitions'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:859:in `columns'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.6/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.6/lib/active_record/model_schema.rb:228:in `yield'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.6/lib/active_record/model_schema.rb:228:in `default'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.6/lib/active_record/model_schema.rb:228:in `columns'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.6/lib/active_record/model_schema.rb:237:in `columns_hash'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.6/lib/active_record/inheritance.rb:19:in `descends_from_active_record?'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.6/lib/active_record/inheritance.rb:25:in `finder_needs_type_condition?'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.6/lib/active_record/base.rb:455:in `relation'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.6/lib/active_record/scoping/named.rb:37:in `scoped'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activerecord-3.2.6/lib/active_record/querying.rb:9:in `where'
/var/nginx/projectx/releases/20120710151049/app/models/staffer.rb:103:in `<class:Staffer>'
/var/nginx/projectx/releases/20120710151049/app/models/staffer.rb:6:in `<top (required)>'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `block in require'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:236:in `load_dependency'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:359:in `require_or_load'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:502:in `load_missing_constant'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:192:in `block in const_missing'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:190:in `each'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:190:in `const_missing'
/var/nginx/projectx/releases/20120710151049/app/admin/users.rb:11:in `block in <top (required)>'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activeadmin-0.4.4/lib/active_admin/dsl.rb:13:in `instance_eval'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activeadmin-0.4.4/lib/active_admin/dsl.rb:13:in `run_registration_block'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activeadmin-0.4.4/lib/active_admin/namespace.rb:178:in `parse_registration_block'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activeadmin-0.4.4/lib/active_admin/namespace.rb:54:in `register'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activeadmin-0.4.4/lib/active_admin/application.rb:99:in `register'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activeadmin-0.4.4/lib/active_admin.rb:74:in `register'
/var/nginx/projectx/releases/20120710151049/app/admin/users.rb:4:in `<top (required)>'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:245:in `load'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:245:in `block in load'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:236:in `load_dependency'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:245:in `load'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activeadmin-0.4.4/lib/active_admin/application.rb:161:in `block in load!'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activeadmin-0.4.4/lib/active_admin/application.rb:161:in `each'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activeadmin-0.4.4/lib/active_admin/application.rb:161:in `load!'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activeadmin-0.4.4/lib/active_admin/application.rb:187:in `routes'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activeadmin-0.4.4/lib/active_admin.rb:78:in `routes'
/var/nginx/projectx/releases/20120710151049/config/routes.rb:114:in `block (2 levels) in <top (required)>'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.6/lib/action_dispatch/routing/mapper.rb:749:in `block in constraints'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.6/lib/action_dispatch/routing/mapper.rb:624:in `scope'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.6/lib/action_dispatch/routing/mapper.rb:749:in `constraints'
/var/nginx/projectx/releases/20120710151049/config/routes.rb:113:in `block in <top (required)>'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.6/lib/action_dispatch/routing/route_set.rb:282:in `instance_exec'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.6/lib/action_dispatch/routing/route_set.rb:282:in `eval_block'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.6/lib/action_dispatch/routing/route_set.rb:260:in `draw'
/var/nginx/projectx/releases/20120710151049/config/routes.rb:3:in `<top (required)>'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:245:in `load'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:245:in `block in load'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:236:in `load_dependency'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:245:in `load'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/application/routes_reloader.rb:40:in `each'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/application/routes_reloader.rb:40:in `load_paths'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/application/routes_reloader.rb:16:in `reload!'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/application.rb:108:in `reload_routes!'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activeadmin-0.4.4/lib/active_admin/reloader.rb:34:in `reload!'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activeadmin-0.4.4/lib/active_admin/reloader.rb:61:in `block in attach!'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:429:in `_run__4352394538915700711__prepare__777820976777011506__callbacks'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:405:in `__run_callback'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:81:in `run_callbacks'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.6/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.6/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/initializable.rb:30:in `instance_exec'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/initializable.rb:30:in `run'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/initializable.rb:55:in `block in run_initializers'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/initializable.rb:54:in `each'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/initializable.rb:54:in `run_initializers'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/application.rb:136:in `initialize!'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/railtie/configurable.rb:30:in `method_missing'
/var/nginx/projectx/releases/20120710151049/config/environment.rb:5:in `<top (required)>'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `block in require'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:236:in `load_dependency'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/application.rb:103:in `require_environment!'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/application.rb:292:in `block (2 levels) in initialize_tasks'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.6/lib/sprockets/assets.rake:93:in `block (2 levels) in <top (required)>'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.6/lib/sprockets/assets.rake:60:in `block (3 levels) in <top (required)>'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.6/lib/sprockets/assets.rake:23:in `invoke_or_reboot_rake_task'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.6/lib/sprockets/assets.rake:29:in `block (2 levels) in <top (required)>'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/bin/rake:23:in `load'
/var/nginx/projectx/shared/bundle/ruby/1.9.1/bin/rake:23:in `<main>'
Tasks: TOP => environment
答案 0 :(得分:1)
将scope
与where
子句一起使用将导致ActiveRecord尝试加载表的列和其他信息,以便它可以预构建ActiveRelation。一个简单的解决方案是将where
部分包装在Proc
或(我最喜欢的)不使用范围并使用类方法。这会做同样的事情,并且随着您的范围变得更加复杂,您会看到它比使用scope
更清晰。
def self.visible
where(:deleted => false)
end