Rails 3.2.10 dump符号格式错误(0x46)



我得到以下错误:

dump format error for symbol(0x46)

在我的rails应用程序实现以下方法后:在模型:

   def common_friends(user)
        (self.following & user.following).count
    end
    def top_5_by_shared_friends
     following.sort_by{|user| common_friends(user)}.reverse.first(5)
    end

在我看来:

<%= render :partial => 'users/user_profile_summary', :collection => @shared_friends, :as => :user %>

in my controller:

@shared_friends = @current_user.top_5_by_shared_friends

现在我只得到这个错误,当我渲染部分在我的视图。例如,如果我删除"渲染部分"行,应用程序加载良好,当然,除了它不显示我想要的内容。

参见下面的应用程序堆栈跟踪:

activerecord (3.2.11) lib/active_record/session_store.rb:60:in `load'
activerecord (3.2.11) lib/active_record/session_store.rb:60:in `unmarshal'
activerecord (3.2.11) lib/active_record/session_store.rb:137:in `data'
activerecord (3.2.11) lib/active_record/session_store.rb:315:in `block in get_session'
activesupport (3.2.11) lib/active_support/benchmarkable.rb:50:in `silence'
activerecord (3.2.11) lib/active_record/session_store.rb:307:in `get_session'
rack (1.4.5) lib/rack/session/abstract/id.rb:251:in `load_session'
actionpack (3.2.11) lib/action_dispatch/middleware/session/abstract_store.rb:49:in `block in load_session'
actionpack (3.2.11) lib/action_dispatch/middleware/session/abstract_store.rb:57:in `stale_session_check!'
actionpack (3.2.11) lib/action_dispatch/middleware/session/abstract_store.rb:49:in `load_session'
rack (1.4.5) lib/rack/session/abstract/id.rb:135:in `load!'
rack (1.4.5) lib/rack/session/abstract/id.rb:127:in `load_for_read!'
rack (1.4.5) lib/rack/session/abstract/id.rb:64:in `has_key?'
actionpack (3.2.11) lib/action_dispatch/middleware/flash.rb:258:in `ensure in call'
actionpack (3.2.11) lib/action_dispatch/middleware/flash.rb:259:in `call'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.11) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.11) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `_run__1662995712724838230__call__2192866322429324249__callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.11) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.11) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.11) lib/rails/rack/logger.rb:18:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.11) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.11) lib/rails/engine.rb:479:in `call'
railties (3.2.11) lib/rails/application.rb:223:in `call'
railties (3.2.11) lib/rails/railtie/configurable.rb:30:in `method_missing'
unicorn (4.6.2) lib/unicorn/http_server.rb:552:in `process_client'
unicorn (4.6.2) lib/unicorn/http_server.rb:632:in `worker_loop'
unicorn (4.6.2) lib/unicorn/http_server.rb:500:in `spawn_missing_workers'
unicorn (4.6.2) lib/unicorn/http_server.rb:142:in `start'
unicorn (4.6.2) bin/unicorn_rails:209:in `<top (required)>'
/home/lgorse/.rvm/gems/ruby-1.9.3-p327/bin/unicorn_rails:19:in `load'
/home/lgorse/.rvm/gems/ruby-1.9.3-p327/bin/unicorn_rails:19:in `<main>'
/home/lgorse/.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `eval'
/home/lgorse/.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `<main>'

我已经确定了错误的原因:

在我的部分中,我调用了:

<li class = "follower_count"><%= pluralize(user.followers.count, "follower") %></li>

仅仅放置user.followers.count就会产生错误。这显然与我的模型方法相冲突,但我根本不明白为什么。

这是关系模型-追随者依赖于:reverse_relationship,我认为错误发生在那里,但我不确定为什么它只发生在这里,而不是程序的其他部分,我也调用追随者:

has_many :relationships, :foreign_key => "follower_id", :dependent => :destroy
    has_many :reverse_relationships, :foreign_key => "followed_id", :dependent => :destroy, :class_name => "Relationship"
    has_many :following,  :through => :relationships, :source => :followed
    has_many :followers, :through => :reverse_relationships, :source => :follower

我想出了一个让网站正常工作的方法。

在我的控制器中,我替换了:
@shared_friends = @current_user.top_5_by_shared_friends

:

@shared_friends = User.find(session['user_id']).top_5_by_shared_friends

这意味着应用程序必须再一次进入数据库,这是多余的,因为它已经在before_filter中基于会话['user_id']这样做了。但由于某些原因,这正确通过,应用程序正常运行。

如果有人有真正的解决方案,而不是像这样的黑客,请发表意见。

否则,我将接受我自己的答案,因为其他人可能用同样的方法解决同样的问题。

只需运行rake tmp:clear,问题就会自行解决。

看到

最新更新