2017-04-11 38 views
3

在我的Rails 4.2.7紅寶石2.3.3應用程序,當我保存特定的多態關聯通過保存的嵌套形式,它給堆棧層次過深的錯誤和rails_admin停止響應。當我從Rails控制檯保存時,它會給出以下錯誤,致命錯誤:重新出現異常錯誤。異常再進入:當保存多態關聯

2.3.3 :001 > Post.last.links 
    Post Load (10.3ms) SELECT "posts".* FROM "posts" ORDER BY "posts"."id" DESC LIMIT 1 
    Link Load (0.8ms) SELECT "links".* FROM "links" WHERE "links"."linked_item_id" = $1 AND "links"."linked_item_type" = $2 [["linked_item_id", 112], ["linked_item_type", "Post"]] 
=> #<ActiveRecord::Associations::CollectionProxy []> 
2.3.3 :002 > Post.last.links.create(name: 'see details', link: 'http://www.google.com/') 
    Post Load (3.7ms) SELECT "posts".* FROM "posts" ORDER BY "posts"."id" DESC LIMIT 1 
    (1.2ms) BEGIN 
    SQL (4.1ms) INSERT INTO "links" ("name", "link", "linked_item_id", "linked_item_type", "target", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id" [["name", "see details"], ["link", "http://www.google.com/"], ["linked_item_id", 112], ["linked_item_type", "Post"], ["target", "_blank"], ["created_at", "2017-04-11 15:34:25.320118"], ["updated_at", "2017-04-11 15:34:25.320118"]] 
    (0.3ms) ROLLBACK 
fatal: exception reentered 
    from /Users/starwar/.rvm/gems/[email protected]/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/transaction.rb:187:in `rescue in within_new_transaction' 
    from /Users/starwar/.rvm/gems/[email protected]/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/transaction.rb:201:in `within_new_transaction' 
    from /Users/starwar/.rvm/gems/[email protected]/gems/activerecord-4.2.7.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction' 
    from /Users/starwar/.rvm/gems/[email protected]/gems/activerecord-4.2.7.1/lib/active_record/transactions.rb:220:in `transaction' 
    from /Users/starwar/.rvm/gems/[email protected]/gems/activerecord-4.2.7.1/lib/active_record/associations/collection_association.rb:182:in `transaction' 
    from /Users/starwar/.rvm/gems/[email protected]/gems/activerecord-4.2.7.1/lib/active_record/associations/collection_association.rb:492:in `_create_record' 
    from /Users/starwar/.rvm/gems/[email protected]/gems/activerecord-4.2.7.1/lib/active_record/associations/has_many_association.rb:187:in `_create_record' 
    from /Users/starwar/.rvm/gems/[email protected]/gems/activerecord-4.2.7.1/lib/active_record/associations/collection_association.rb:153:in `create' 
    from /Users/starwar/.rvm/gems/[email protected]/gems/activerecord-4.2.7.1/lib/active_record/associations/collection_proxy.rb:290:in `create' 
    from (irb):2 
    from /Users/starwar/.rvm/gems/[email protected]/gems/railties-4.2.7.1/lib/rails/commands/console.rb:110:in `start' 
    from /Users/starwar/.rvm/gems/[email protected]/gems/railties-4.2.7.1/lib/rails/commands/console.rb:9:in `start' 
    from /Users/starwar/.rvm/gems/[email protected]/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:68:in `console' 
    from /Users/starwar/.rvm/gems/[email protected]/gems/railties-4.2.7.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!' 
    from /Users/starwar/.rvm/gems/[email protected]/gems/railties-4.2.7.1/lib/rails/commands.rb:17:in `<top (required)>' 
    from bin/rails:4:in `require' 
    from bin/rails:4:in `<main>' 

這裏是

class Link < ActiveRecord::Base 
    extend Enumerize 
    enumerize :target, in: [:_blank, :_self, :_top, :_parent], default: :_blank 
    # Associations 
    belongs_to :linked_item, polymorphic: true, touch: true 

    # Validations 

    validates_presence_of :link 
    validates_presence_of :name 
    validates :link, :url => { allow_nil: false } 

    # Scopes 
    scope :sorted, -> { order(created_at: :asc) } 
end 

這完全相同的代碼被部署在Heroku我的Post模型

class Post < ActiveRecord::Base 
    has_many :links, -> { order(created_at: :asc) }, as: :linked_item, dependent: :destroy 
    accepts_nested_attributes_for :links, allow_destroy: true 

我的鏈接模型的相關部分,它工作正常,但在我的本地機器,它不工作。 而當軌道服務器停止響應那麼我殺掉進程和它說

[NOTE] 
You may have encountered a bug in the Ruby interpreter or extension libraries. 
Bug reports are welcome. 
For details: http://www.ruby-lang.org/bugreport.html 

和令人驚訝的我的測試都通過,但我不能夠通過Rails的控制檯或rails_admin面板添加任何東西到具有模型通過填充嵌套形式來實現多態關聯。

感謝,

回答

0

我已經解決了這個問題,我沒有下面的事情,我不知道這其中的一個解決它。

  • 我正在使用postgres 9.2並更新到最新的9.6。我認爲沒有解決這個問題,我應該這樣做,而且我也是這樣做的,因爲heroku運行9.5,所以我認爲是時候升級。我不建議你這樣做。

貝婁是我相信解決這個問題的步驟。

  • 更新了Rails 4.2.7.1到Rails 4.2.8。我不認爲這解決了這個問題。

  • 我正在運行使用Searchkick的彈性搜索引擎,我重新編制索引我的模型數據進行更改後。

  • 更新OJ寶石最新版本(2.16.1),並下調enumerize到次要版本(2.0.1)和更新Friendly_id寶石最新版本(5.2.1)。我認爲這解決了這個問題。

謝謝,