尝试运行“rake db:seed”时验证错误

时间:2015-03-16 03:07:46

标签: ruby-on-rails ruby refinerycms

我的同事和我正在使用Rails 4.1.8。我们正在研究裸机(没有Docker,没有VM)。我的cowerker使用的是Ruby 2.0.0,而我使用的是2.1.5。我们同意转向同一版本。

我的同事开始研究这个问题而没有把它放到Github上。他用scp将它放在亚马逊的服务器上。我的同事安装了RefineryCMS的视频插件,可以运行:

rake db:seed

我不知道他是在使用bundle exec还是依赖系统宝石。

我使用scp从亚马逊下载代码。我得到了.gitignore通常会保留的所有文件。我安装了会员插件,如果我运行命令:

bundle exec rake db:seed

我收到错误:

ActiveRecord::RecordInvalid: Validation failed: Title can't be blank, Parts title can't be blank

并且堆栈跟踪指向:

/Users/cerhovice/projects/patton/royalbeauty/vendor/extensions/videos/db/seeds.rb:10:in `block in <top (required)>'

完整的回溯看起来像这样:

/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/validations.rb:57:in `save!'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/attribute_methods/dirty.rb:29:in `save!'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/transactions.rb:273:in `block in save!'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/transactions.rb:329:in `block in with_transaction_returning_status'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `block in transaction'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/database_statements.rb:209:in `within_new_transaction'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/database_statements.rb:201:in `transaction'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/transactions.rb:208:in `transaction'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/transactions.rb:326:in `with_transaction_returning_status'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/transactions.rb:273:in `save!'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/protected_attributes-1.0.8/lib/active_record/mass_assignment_security/validations.rb:17:in `create!'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/relation.rb:147:in `block in create!'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/relation.rb:292:in `scoping'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/relation.rb:147:in `create!'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/relation.rb:155:in `first_or_create!'
/Users/cerhovice/projects/patton/royalbeauty/vendor/extensions/videos/db/seeds.rb:10:in `block in <top (required)>'
/Users/cerhovice/projects/patton/royalbeauty/vendor/extensions/videos/db/seeds.rb:1:in `each'
/Users/cerhovice/projects/patton/royalbeauty/vendor/extensions/videos/db/seeds.rb:1:in `<top (required)>'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:241:in `load'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:241:in `block in load'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:241:in `load'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/engine.rb:543:in `load_seed'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/railtie.rb:194:in `public_send'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/railtie.rb:194:in `method_missing'
/Users/cerhovice/projects/patton/royalbeauty/db/seeds.rb:13:in `<top (required)>'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:241:in `load'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:241:in `block in load'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:241:in `load'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/engine.rb:543:in `load_seed'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/tasks/database_tasks.rb:200:in `load_seed'
/Users/cerhovice/projects/patton/royalbeauty/vendor/bundle/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/railties/databases.rake:174:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:seed

我打开了该文件,并检查了partindex的值:

Refinery::Page.where(link_url: (url = "/videos")).first_or_create!(
  title: 'Videos',
  deletable: false,
  menu_match: "^#{url}(\/|\/.+?|)$"
) do |page|
  Refinery::Pages.default_parts.each_with_index do |part, index|
    [part, index] # => [Body, 0], then [Side Body, 1]
    page.parts.build title: part, body: nil, position: index
  end
end if defined?(Refinery::Page)

尽管堆栈跟踪说的是,如果在我刚刚安装的插件中​​发生此错误会更有意义,所以我打开了:

vendor/bundle/ruby/2.1.0/bundler/gems/refinerycms_membership-cd49cac06a43/db/seeds.rb

我添加了一些put语句。这些从未在终端中显示。相反,我得到上面的输出,然后是rake aborted!

它适用于我的同事,但不适合我。 Rails程序员通常会如何调试这种问题?我该如何开始调试呢?我不是要求RefineryCMS提供帮助。

来自log / development.log:

 (0.1ms)  SELECT MAX("refinery_user_plugins"."position") AS max_id FROM "refinery_user_plugins"  WHERE "refinery_user_plugins"."user_id" = ?  [["user_id", 4]]

Refinery::UserPlugin Load (0.1ms)  SELECT  "refinery_user_plugins".* FROM "refinery_user_plugins"  WHERE "refinery_user_plugins"."user_id" = ? AND "refinery_user_plugins"."name" = 'refinerycms-videos'  ORDER BY position ASC LIMIT 1  [["user_id", 4]]

Refinery::Page Load (0.2ms)  SELECT  "refinery_pages".* FROM "refinery_pages"  WHERE "refinery_pages"."link_url" = '/videos'  ORDER BY "refinery_pages"."id" ASC LIMIT 1

WARNING: Can't mass-assign protected attributes for Refinery::Page: title, deletable, menu_match

WARNING: Can't mass-assign protected attributes for Refinery::PagePart: title, body, position

WARNING: Can't mass-assign protected attributes for Refinery::PagePart: title, body, position
(0.1ms)  begin transaction

Refinery::PagePart Exists (0.2ms)  SELECT  1 AS one FROM "refinery_page_parts"  WHERE ("refinery_page_parts"."title" IS NULL AND "refinery_page_parts"."refinery_page_id" IS NULL) LIMIT 1

Refinery::PagePart Exists (0.1ms)  SELECT  1 AS one FROM "refinery_page_parts"  WHERE ("refinery_page_parts"."title" IS NULL AND "refinery_page_parts"."refinery_page_id" IS NULL) LIMIT 1
 (0.1ms)  rollback transaction

0 个答案:

没有答案