1

我在使用 auto_html 中断 Rails 迁移时遇到了麻烦。我在新的 db/first 迁移运行中得到了这个跟踪(见结尾,因为它很大)。

我通过在模型中注释掉这样的代码来解决它:

 auto_html_for :story do
    strip_tags
    html_escape
  end

有关如何处理此问题的任何建议,以便迁移正常运行而无需注释掉?

$rake db:migrate

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
PG::Error: ERROR:  relation "profiles" does not exist
LINE 4:              WHERE a.attrelid = '"profiles"'::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 = '"profiles"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1158:in `async_exec'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1158:in `exec_no_cache'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:664:in `block in exec_query'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:663:in `exec_query'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1283:in `column_definitions'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:859:in `columns'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activerecord-3.2.8/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activerecord-3.2.8/lib/active_record/model_schema.rb:228:in `yield'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activerecord-3.2.8/lib/active_record/model_schema.rb:228:in `default'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activerecord-3.2.8/lib/active_record/model_schema.rb:228:in `columns'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activerecord-3.2.8/lib/active_record/model_schema.rb:248:in `column_names'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/auto_html-1.6.0/lib/auto_html/auto_html_for.rb:21:in `auto_html_for'
/Users/heather/3r/website/app/models/profile.rb:73:in `<class:Profile>'
/Users/heather/3r/website/app/models/profile.rb:1:in `<top (required)>'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:469:in `load'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:469:in `block in load_file'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:639:in `new_constants_in'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:468:in `load_file'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:353:in `require_or_load'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:502:in `load_missing_constant'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:192:in `block in const_missing'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:190:in `each'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:190:in `const_missing'
/Users/heather/3r/website/app/admin/profiles.rb:1:in `<top (required)>'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `load'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `block in load'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `load'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activeadmin-0.5.1/lib/active_admin/application.rb:190:in `block in load!'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activeadmin-0.5.1/lib/active_admin/application.rb:190:in `each'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activeadmin-0.5.1/lib/active_admin/application.rb:190:in `load!'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activeadmin-0.5.1/lib/active_admin/application.rb:213:in `routes'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activeadmin-0.5.1/lib/active_admin.rb:79:in `routes'
/Users/heather/3r/website/config/routes.rb:41:in `block in <top (required)>'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:282:in `instance_exec'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:282:in `eval_block'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:260:in `draw'
/Users/heather/3r/website/config/routes.rb:28:in `<top (required)>'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `load'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `block in load'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `load'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/railties-3.2.8/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/railties-3.2.8/lib/rails/application/routes_reloader.rb:40:in `each'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/railties-3.2.8/lib/rails/application/routes_reloader.rb:40:in `load_paths'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/railties-3.2.8/lib/rails/application/routes_reloader.rb:16:in `reload!'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/railties-3.2.8/lib/rails/application.rb:108:in `reload_routes!'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activeadmin-0.5.1/lib/active_admin/reloader.rb:34:in `reload!'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activeadmin-0.5.1/lib/active_admin/reloader.rb:61:in `block in attach!'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:429:in `_run__574638835061218640__prepare__331886071729593740__callbacks'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:405:in `__run_callback'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/actionpack-3.2.8/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/actionpack-3.2.8/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/railties-3.2.8/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `instance_exec'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `run'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/railties-3.2.8/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `each'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `run_initializers'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/railties-3.2.8/lib/rails/application.rb:136:in `initialize!'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/railties-3.2.8/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/heather/3r/website/config/environment.rb:5:in `<top (required)>'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `block in require'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/railties-3.2.8/lib/rails/application.rb:103:in `require_environment!'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/gems/railties-3.2.8/lib/rails/application.rb:295:in `block (2 levels) in initialize_tasks'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
/Users/heather/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/task.rb:187:in `block in invoke_prerequisites'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/task.rb:185:in `each'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/task.rb:185:in `invoke_prerequisites'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/task.rb:165:in `block in invoke_with_call_chain'
/Users/heather/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/application.rb:143:in `invoke_task'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/application.rb:101:in `each'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/application.rb:101:in `block in top_level'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/application.rb:110:in `run_with_threads'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/application.rb:95:in `top_level'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/application.rb:73:in `block in run'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/bin/rake:19:in `load'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@global/bin/rake:19:in `<main>'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/bin/ruby_noexec_wrapper:14:in `eval'
/Users/heather/.rvm/gems/ruby-1.9.3-p392@3r/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:migrate => environment
Heathers-MacBook-Pro:website heather$
4

1 回答 1

1

我确实找到了一个解决方案,基本上如果 rake 正在运行 - 禁用 auto_html。这是 auto_html 初始化程序中的代码:

if File.basename($0) == 'rake' && ARGV.grep(/db:/)
  class ActiveRecord::Base
    def self.auto_html_for(field, &block)
        #nothing
    end
  end

else

  AutoHtml.add_filter(:strip_tags).with({}) do |text, options|
    view = ActionView::Base.new
    view.strip_tags text
  end
  AutoHtml.add_filter(:autolink).with({}) do |text, options|
    view = ActionView::Base.new
    view.auto_link(text, :html => { :target => '_blank', :rel => "nofollow" })
  end


  class ActiveRecord::Base
    class << self
      alias_method :auto_html_for!, :auto_html_for
    end

    def self.auto_html_for(field, &block)
      auto_html_for!(field, &block)
    end
  end

end
于 2013-06-07T13:59:05.367 回答