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

时间:2013-05-09 21:44:18

标签: ruby-on-rails ruby-on-rails-3 activerecord

我收到以下错误:

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 %>

在我的控制器中:

@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

2 个答案:

答案 0 :(得分:0)

好吧,我想出了让网站正常运行的黑客攻击。这是:

在我的控制器中,我更换了:

@shared_friends = @current_user.top_5_by_shared_friends

使用:

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

这意味着应用程序必须再次访问数据库,这是多余的,因为它已经基于before_filter中的session ['user_id']执行此操作。但由于某些原因,这正确传递,应用程序运行正常。

如果有人有真正的解决方案,而不是像这样的黑客,请加入。

否则我会接受我自己的答案 - 鉴于其他人可能会用相同的黑客解决同样的问题。

答案 1 :(得分:0)

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

请参阅here