4

データベースがクリーンで、テーブルがなく、テスト中やデプロイ先の新しいサーバーを設定するときによく発生する場合、assets:precompile などの多くの rake タスクが次のエラーで失敗します。

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)

コメントアウトすると、少なくとも assets:precompile が機能します。

すべてが 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
4

1 に答える 1

1

句を使用scopeすると、whereActiveRecord はテーブルの列やその他の情報をロードしようとするため、ActiveRelation を事前に構築できます。where簡単な解決策は、その部分を でラップするかProc、(私のお気に入り) スコープを使用せず、代わりにクラス メソッドを使用することです。これは同じことを行い、スコープがより複雑になるにつれて、 を使用するよりもきれいになりますscope

def self.visible
  where(:deleted => false)
end
于 2012-07-10T15:59:32.683 に答える