- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下型号:
class Review < ActiveRecord::Base
attr_accessible :votes_sum
has_many :votes, :as => :voteable,
:after_add => :sum_votes,
:after_remove => :sum_votes
def sum_votes
update_attribute(:votes_sum, votes.sum(:value))
end
end
class Vote < ActiveRecord::Base
attr_accessible :value
belongs_to :voteable, :polymorphic => true
end
wrong number of arguments (1 for 0)
def sum_votes
app/models/review.rb:13:in `sum_votes'
activerecord (3.2.11) lib/active_record/associations/collection_association.rb:507:in `block in callback'
activerecord (3.2.11) lib/active_record/associations/collection_association.rb:504:in `each'
activerecord (3.2.11) lib/active_record/associations/collection_association.rb:504:in `callback'
activerecord (3.2.11) lib/active_record/associations/collection_association.rb:352:in `add_to_target'
activerecord (3.2.11) lib/active_record/associations/collection_association.rb:112:in `build'
C:in `build'
app/models/user.rb:251:in `build_vote'
app/controllers/votes_controller.rb:9:in `create'
actionpack (3.2.11) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.11) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.11) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.11) lib/active_support/callbacks.rb:425:in `_run__943985968__process_action__580999264__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_process_action_callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.11) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.11) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.11) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.11) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.11) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.11) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.11) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.11) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.11) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.11) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:601:in `call'
warden (1.2.1) lib/warden/manager.rb:35:in `block in call'
warden (1.2.1) lib/warden/manager.rb:34:in `catch'
warden (1.2.1) lib/warden/manager.rb:34:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.4) lib/rack/etag.rb:23:in `call'
rack (1.4.4) lib/rack/conditionalget.rb:35:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.4) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.4) 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__942047474__call__281283767__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:16:in `block in call'
activesupport (3.2.11) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.11) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.4) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.4) 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.4) 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'
rack (1.4.4) lib/rack/content_length.rb:14:in `call'
railties (3.2.11) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.4) lib/rack/handler/webrick.rb:59:in `service'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
最佳答案
Mongoid 将关联集合中创建的文档传递给回调方法,参见此处:Relation callbacks
即使您不使用它,您也必须更改方法的签名才能接收该文档(我也改进了该方法,使用 inc
):
def sum_votes(vote)
inc(:votes_sum, 1)
end
关于ruby-on-rails - rails : after_add giving error wrong number of arguments (1 for 0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14553085/
这个问题在这里已经有了答案: java.lang.IllegalArgumentException: The servlets named [X] and [Y] are both mapped t
我无法让我的 WebRTC 代码正常工作。我相信我所做的一切都是正确的,但它仍然无法正常工作。为什么 ontrack 这么早就被调用有些奇怪,也许它应该是那样的。 该网站使用 javascript 代
使用 Mac OSX 优胜美地 (10.10.4): rails -v => Rails 4.2.3 ruby -v => ruby 2.2.2p95 遵循这些说明的组合: https://www
您好,我正在尝试使用(缓存的)已编译的 lambda 表达式来访问属性,与使用 PropertyInfo.GetValue()/SetValue() 方法调用相比,我确实得到了更好(即更快)的结果。然
我编写此代码是为了获取学生的字母成绩并计算他们的 GPA。当我运行该程序时,我可以正确获取学生的姓名和科目,但无法显示成绩或 GPA。 示例输入: Sally 1 A N 示例输出: Enter St
我一直在编写这段代码,根据这本书应该可以做到这一点: Write a script that creates and calls a stored procedure named test. This
我真的很难创建一个具有以下基本格式的有效多维 JavaScript 数组: var countries = [ { "country": "UK", "properties": {
我有一个小型 Python OOP 程序,其中 2 个类 Flan 和 Outil 继承自父类(super class) Part。 我的问题是,当我调用 Flan 时一切正常,但是当我调用 Outi
我目前正在尝试使用通用监听器来编写事件系统。 所有监听器都应添加到单个 EventSource 对象,该对象将为特定事件调用其 receiveEvent() 方法。 事件源: public class
我正在通过我的 PHP 应用程序发送电子邮件。但是,它们被 Gmail 标记为垃圾邮件。这是我发送电子邮件的方式(PHP): $headers = "From: test@bookmytakeout.
我已经正式走到了穷途末路的地步。我找不到我做错了什么。我完成的这个程序几乎与我几天前编写的另一个程序一模一样,但我在编译时遇到了问题。我不知道为什么输出线上出现错误。请帮忙: 这是正在运行的文件: p
---编辑:我不允许使用任何包或预置方法。不用担心,我不想让你做我的“作业”,我只需要一点提示!---我发现these interesting Algorithms 。我想使用按位添加方法。我的问题是
我制作了一个小程序,尝试使用 conn.getOutputStream(); 检索 URLConnection 对象输出流。当我尝试执行此操作时,我的小程序抛出异常 java.net.UnknownS
每当我尝试在 SVN 中合并时,我都会遇到成堆的树冲突。好吧,就此示例脚本而言,只有一个,但仍然如此。 #!/bin/bash svnadmin create repo svn checkout fi
我开始为 Scala 中的 X500PrincipalBuilder 类编写单元测试。这是我的测试代码: import org.junit.runner.RunWith import org.scal
我正在用 python 编写我的第一个程序,它必须模拟粒子(两种气体)的混合。我不知道我这个功能做错了什么。我不希望颗粒离开某些区域,即容器的壁。我使用 VPython。 def poruszanie
我正在尝试求解三角方程组,但我认为 Python 没有生成正确的解。我试图解决的方程: 1 − 2cosθ1 + 2cosθ2 − 2cosθ3 = −0.8 1 − 2cos5θ1 + 2cos5θ
这个问题已经有答案了: TypeError: worker() takes 0 positional arguments but 1 was given [duplicate] (11 个回答) 已关
大家好,我正在努力解决这个问题 编写一个 C 程序,计算弹丸在撞击地面之前行进的距离(即射程)、弹丸撞击地面所需的时间以及弹丸飞行中的最大高度(给定角度)它被射向空中,以及发射时的初始速度(速度)。我
我编写了代码来计算 QuickSort 中完成的比较次数。 每当对长度为 m 的数组执行快速排序时,该算法都会将比较次数增加 m-1(因为主元将与除自身以外的所有内容进行比较)。 枢轴的选择始终是数组
我是一名优秀的程序员,十分优秀!