2013-03-21 79 views
1

我遇到了auto_html打破rails遷移的麻煩。我在一個新的數據庫/第一次遷移運行中得到這個跟蹤(參見end,因爲它很大)。auto_html打破rails遷移

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/[email protected]/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1158:in `async_exec' 
/Users/heather/.rvm/gems/[email protected]/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1158:in `exec_no_cache' 
/Users/heather/.rvm/gems/[email protected]/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:664:in `block in exec_query' 
/Users/heather/.rvm/gems/[email protected]/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log' 
/Users/heather/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
/Users/heather/.rvm/gems/[email protected]/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log' 
/Users/heather/.rvm/gems/[email protected]/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:663:in `exec_query' 
/Users/heather/.rvm/gems/[email protected]/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:1283:in `column_definitions' 
/Users/heather/.rvm/gems/[email protected]/gems/activerecord-3.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:859:in `columns' 
/Users/heather/.rvm/gems/[email protected]/gems/activerecord-3.2.8/lib/active_record/connection_adapters/schema_cache.rb:12:in `block in initialize' 
/Users/heather/.rvm/gems/[email protected]/gems/activerecord-3.2.8/lib/active_record/model_schema.rb:228:in `yield' 
/Users/heather/.rvm/gems/[email protected]/gems/activerecord-3.2.8/lib/active_record/model_schema.rb:228:in `default' 
/Users/heather/.rvm/gems/[email protected]/gems/activerecord-3.2.8/lib/active_record/model_schema.rb:228:in `columns' 
/Users/heather/.rvm/gems/[email protected]/gems/activerecord-3.2.8/lib/active_record/model_schema.rb:248:in `column_names' 
/Users/heather/.rvm/gems/[email protected]/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-[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:469:in `load' 
/Users/heather/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:469:in `block in load_file' 
/Users/heather/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:639:in `new_constants_in' 
/Users/heather/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:468:in `load_file' 
/Users/heather/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:353:in `require_or_load' 
/Users/heather/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:502:in `load_missing_constant' 
/Users/heather/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:192:in `block in const_missing' 
/Users/heather/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:190:in `each' 
/Users/heather/.rvm/gems/[email protected]/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/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `load' 
/Users/heather/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `block in load' 
/Users/heather/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency' 
/Users/heather/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `load' 
/Users/heather/.rvm/gems/[email protected]/gems/activeadmin-0.5.1/lib/active_admin/application.rb:190:in `block in load!' 
/Users/heather/.rvm/gems/[email protected]/gems/activeadmin-0.5.1/lib/active_admin/application.rb:190:in `each' 
/Users/heather/.rvm/gems/[email protected]/gems/activeadmin-0.5.1/lib/active_admin/application.rb:190:in `load!' 
/Users/heather/.rvm/gems/[email protected]/gems/activeadmin-0.5.1/lib/active_admin/application.rb:213:in `routes' 
/Users/heather/.rvm/gems/[email protected]/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/[email protected]/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:282:in `instance_exec' 
/Users/heather/.rvm/gems/[email protected]/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:282:in `eval_block' 
/Users/heather/.rvm/gems/[email protected]/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/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `load' 
/Users/heather/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `block in load' 
/Users/heather/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency' 
/Users/heather/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `load' 
/Users/heather/.rvm/gems/[email protected]/gems/railties-3.2.8/lib/rails/application/routes_reloader.rb:40:in `block in load_paths' 
/Users/heather/.rvm/gems/[email protected]/gems/railties-3.2.8/lib/rails/application/routes_reloader.rb:40:in `each' 
/Users/heather/.rvm/gems/[email protected]/gems/railties-3.2.8/lib/rails/application/routes_reloader.rb:40:in `load_paths' 
/Users/heather/.rvm/gems/[email protected]/gems/railties-3.2.8/lib/rails/application/routes_reloader.rb:16:in `reload!' 
/Users/heather/.rvm/gems/[email protected]/gems/railties-3.2.8/lib/rails/application.rb:108:in `reload_routes!' 
/Users/heather/.rvm/gems/[email protected]/gems/activeadmin-0.5.1/lib/active_admin/reloader.rb:34:in `reload!' 
/Users/heather/.rvm/gems/[email protected]/gems/activeadmin-0.5.1/lib/active_admin/reloader.rb:61:in `block in attach!' 
/Users/heather/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:429:in `_run__574638835061218640__prepare__331886071729593740__callbacks' 
/Users/heather/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:405:in `__run_callback' 
/Users/heather/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks' 
/Users/heather/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:81:in `run_callbacks' 
/Users/heather/.rvm/gems/[email protected]/gems/actionpack-3.2.8/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!' 
/Users/heather/.rvm/gems/[email protected]/gems/actionpack-3.2.8/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!' 
/Users/heather/.rvm/gems/[email protected]/gems/railties-3.2.8/lib/rails/application/finisher.rb:47:in `block in <module:Finisher>' 
/Users/heather/.rvm/gems/[email protected]/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `instance_exec' 
/Users/heather/.rvm/gems/[email protected]/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `run' 
/Users/heather/.rvm/gems/[email protected]/gems/railties-3.2.8/lib/rails/initializable.rb:55:in `block in run_initializers' 
/Users/heather/.rvm/gems/[email protected]/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `each' 
/Users/heather/.rvm/gems/[email protected]/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `run_initializers' 
/Users/heather/.rvm/gems/[email protected]/gems/railties-3.2.8/lib/rails/application.rb:136:in `initialize!' 
/Users/heather/.rvm/gems/[email protected]/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/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require' 
/Users/heather/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `block in require' 
/Users/heather/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency' 
/Users/heather/.rvm/gems/[email protected]/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require' 
/Users/heather/.rvm/gems/[email protected]/gems/railties-3.2.8/lib/rails/application.rb:103:in `require_environment!' 
/Users/heather/.rvm/gems/[email protected]/gems/railties-3.2.8/lib/rails/application.rb:295:in `block (2 levels) in initialize_tasks' 
/Users/heather/.rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/task.rb:228:in `call' 
/Users/heather/.rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute' 
/Users/heather/.rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/task.rb:223:in `each' 
/Users/heather/.rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute' 
/Users/heather/.rvm/gems/[email protected]/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/[email protected]/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain' 
/Users/heather/.rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/task.rb:187:in `block in invoke_prerequisites' 
/Users/heather/.rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/task.rb:185:in `each' 
/Users/heather/.rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/task.rb:185:in `invoke_prerequisites' 
/Users/heather/.rvm/gems/[email protected]/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/[email protected]/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain' 
/Users/heather/.rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke' 
/Users/heather/.rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/application.rb:143:in `invoke_task' 
/Users/heather/.rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/application.rb:101:in `block (2 levels) in top_level' 
/Users/heather/.rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/application.rb:101:in `each' 
/Users/heather/.rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/application.rb:101:in `block in top_level' 
/Users/heather/.rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/application.rb:110:in `run_with_threads' 
/Users/heather/.rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/application.rb:95:in `top_level' 
/Users/heather/.rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/application.rb:73:in `block in run' 
/Users/heather/.rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling' 
/Users/heather/.rvm/gems/[email protected]/gems/rake-10.0.3/lib/rake/application.rb:70:in `run' 
/Users/heather/.rvm/gems/[email protected]/gems/rake-10.0.3/bin/rake:33:in `<top (required)>' 
/Users/heather/.rvm/gems/[email protected]/bin/rake:19:in `load' 
/Users/heather/.rvm/gems/[email protected]/bin/rake:19:in `<main>' 
/Users/heather/.rvm/gems/[email protected]/bin/ruby_noexec_wrapper:14:in `eval' 
/Users/heather/.rvm/gems/[email protected]/bin/ruby_noexec_wrapper:14:in `<main>' 
Tasks: TOP => db:migrate => environment 
Heathers-MacBook-Pro:website heather$ 
+0

我不知道這個問題的答案,但我仍然要感謝你讓我真棒[auto_haml寶石(https://github.com/dejan/auto_html),所以你得到我的讚許! – weltschmerz 2013-03-21 22:20:30

回答

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 
+0

它與設計有關。如果你拿出設計路線,它也可以......也不知道爲什麼會發生這種情況 – Marc 2014-01-03 03:31:09