我收到以下错误:
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