- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 Rails 4 时遇到这个错误:
wrong number of arguments (0 for 1)
在 Controller 中运行这段代码时:
class CommentsController < ApplicationController
def create
@comment = @current_user.comments.build(comment_params)
if @comment.save
redirect_to :back, flash: { success: "Comment was updated." }
else
redirect_to :back, flash: { error: "There was an issue with your comment." }, comment: { content: params[:comment][:content] }
end
end
private
def comment_params
params.require(:comment).permit(:post_id, :content)
end
end
这是模型:
class Comment < ActiveRecord::Base
belongs_to :post
belongs_to :user
validates_presence_of :content
validates_length_of :attribute, minimum: 20
end
这是堆栈跟踪:
block in ActiveModel::Validations::LengthValidator#validate
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activemodel/lib/active_model/validator.rb, line 151
ActiveModel::Validations::LengthValidator#validate
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activemodel/lib/active_model/validator.rb, line 150
Comment#_callback_before_112
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activesupport/lib/active_support/callbacks.rb, line 281
Comment#_run__664310716__validate__callbacks
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activesupport/lib/active_support/callbacks.rb, line 388
Comment#run_callbacks
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activesupport/lib/active_support/callbacks.rb, line 78
Comment#run_validations!
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activemodel/lib/active_model/validations.rb, line 330
block in Comment#run_validations!
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activemodel/lib/active_model/validations/callbacks.rb, line 106
Comment#_run__664310716__validation__callbacks
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activesupport/lib/active_support/callbacks.rb, line 374
Comment#run_callbacks
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activesupport/lib/active_support/callbacks.rb, line 78
Comment#run_validations!
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activemodel/lib/active_model/validations/callbacks.rb, line 106
Comment#valid?
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activemodel/lib/active_model/validations.rb, line 271
Comment#valid?
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activerecord/lib/active_record/validations.rb, line 70
Comment#perform_validations
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activerecord/lib/active_record/validations.rb, line 78
Comment#save!
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activerecord/lib/active_record/validations.rb, line 57
Comment#save!
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activerecord/lib/active_record/attribute_methods/dirty.rb, line 41
block in Comment#save!
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activerecord/lib/active_record/transactions.rb, line 275
block in Comment#with_transaction_returning_status
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activerecord/lib/active_record/transactions.rb, line 326
block in ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#transaction
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb, line 202
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#within_new_transaction
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb, line 210
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#transaction
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb, line 202
Comment.transaction
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activerecord/lib/active_record/transactions.rb, line 209
Comment#with_transaction_returning_status
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activerecord/lib/active_record/transactions.rb, line 323
Comment#save!
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activerecord/lib/active_record/transactions.rb, line 275
CommentsController#create
app/controllers/comments_controller.rb, line 4
CommentsController#send_action
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_controller/metal/implicit_render.rb, line 4
CommentsController#process_action
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/abstract_controller/base.rb, line 189
CommentsController#process_action
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_controller/metal/rendering.rb, line 10
block in CommentsController#process_action
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/abstract_controller/callbacks.rb, line 18
CommentsController#_run__1046107247__process_action__callbacks
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activesupport/lib/active_support/callbacks.rb, line 414
CommentsController#run_callbacks
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activesupport/lib/active_support/callbacks.rb, line 78
CommentsController#process_action
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/abstract_controller/callbacks.rb, line 17
CommentsController#process_action
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_controller/metal/rescue.rb, line 29
block in CommentsController#process_action
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_controller/metal/instrumentation.rb, line 31
block in ActiveSupport::Notifications.instrument
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activesupport/lib/active_support/notifications.rb, line 158
ActiveSupport::Notifications::Instrumenter#instrument
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activesupport/lib/active_support/notifications/instrumenter.rb, line 20
ActiveSupport::Notifications.instrument
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activesupport/lib/active_support/notifications.rb, line 158
CommentsController#process_action
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_controller/metal/instrumentation.rb, line 30
CommentsController#process_action
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_controller/metal/params_wrapper.rb, line 245
CommentsController#process_action
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activerecord/lib/active_record/railties/controller_runtime.rb, line 18
CommentsController#process
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/abstract_controller/base.rb, line 136
CommentsController#process
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/abstract_controller/rendering.rb, line 44
CommentsController#dispatch
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_controller/metal.rb, line 196
CommentsController#dispatch
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_controller/metal/rack_delegation.rb, line 13
block in CommentsController.action
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_controller/metal.rb, line 232
ActionDispatch::Routing::RouteSet::Dispatcher#dispatch
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_dispatch/routing/route_set.rb, line 80
ActionDispatch::Routing::RouteSet::Dispatcher#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_dispatch/routing/route_set.rb, line 48
block in ActionDispatch::Journey::Router#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_dispatch/journey/router.rb, line 69
ActionDispatch::Journey::Router#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_dispatch/journey/router.rb, line 57
ActionDispatch::Routing::RouteSet#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_dispatch/routing/route_set.rb, line 645
ClientSideValidations::Middleware::Validators#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/client_side_validations-6855ba7031d4/lib/client_side_validations/middleware.rb, line 21
Rack::ETag#call
(gem) rack-1.5.2/lib/rack/etag.rb, line 23
Rack::ConditionalGet#call
(gem) rack-1.5.2/lib/rack/conditionalget.rb, line 35
Rack::Head#call
(gem) rack-1.5.2/lib/rack/head.rb, line 11
ActionDispatch::ParamsParser#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_dispatch/middleware/params_parser.rb, line 27
ActionDispatch::Flash#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_dispatch/middleware/flash.rb, line 241
ActionDispatch::Session::EncryptedCookieStore#context
(gem) rack-1.5.2/lib/rack/session/abstract/id.rb, line 225
ActionDispatch::Session::EncryptedCookieStore#call
(gem) rack-1.5.2/lib/rack/session/abstract/id.rb, line 220
ActionDispatch::Cookies#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_dispatch/middleware/cookies.rb, line 452
ActiveRecord::QueryCache#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activerecord/lib/active_record/query_cache.rb, line 36
ActiveRecord::ConnectionAdapters::ConnectionManagement#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 632
ActiveRecord::Migration::CheckPending#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activerecord/lib/active_record/migration.rb, line 366
block in ActionDispatch::Callbacks#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_dispatch/middleware/callbacks.rb, line 29
ActionDispatch::Callbacks#_run__81458556__call__callbacks
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activesupport/lib/active_support/callbacks.rb, line 374
ActionDispatch::Callbacks#run_callbacks
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activesupport/lib/active_support/callbacks.rb, line 78
ActionDispatch::Callbacks#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_dispatch/middleware/callbacks.rb, line 27
ActionDispatch::Reloader#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_dispatch/middleware/reloader.rb, line 64
ActionDispatch::RemoteIp#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_dispatch/middleware/remote_ip.rb, line 76
BetterErrors::Middleware#protected_app_call
(gem) better_errors-0.7.2/lib/better_errors/middleware.rb, line 84
BetterErrors::Middleware#better_errors_call
(gem) better_errors-0.7.2/lib/better_errors/middleware.rb, line 79
BetterErrors::Middleware#call
(gem) better_errors-0.7.2/lib/better_errors/middleware.rb, line 56
ActionDispatch::DebugExceptions#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb, line 17
ActionDispatch::ShowExceptions#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_dispatch/middleware/show_exceptions.rb, line 30
Rails::Rack::Logger#call_app
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/railties/lib/rails/rack/logger.rb, line 38
block in Rails::Rack::Logger#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/railties/lib/rails/rack/logger.rb, line 21
block in ActiveSupport::Logger#tagged
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activesupport/lib/active_support/tagged_logging.rb, line 67
ActiveSupport::Logger::SimpleFormatter#tagged
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activesupport/lib/active_support/tagged_logging.rb, line 25
ActiveSupport::Logger#tagged
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activesupport/lib/active_support/tagged_logging.rb, line 67
Rails::Rack::Logger#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/railties/lib/rails/rack/logger.rb, line 21
ActionDispatch::RequestId#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_dispatch/middleware/request_id.rb, line 21
Rack::MethodOverride#call
(gem) rack-1.5.2/lib/rack/methodoverride.rb, line 21
Rack::Runtime#call
(gem) rack-1.5.2/lib/rack/runtime.rb, line 17
ActiveSupport::Cache::Strategy::LocalCache::Middleware#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/activesupport/lib/active_support/cache/strategy/local_cache.rb, line 72
Rack::Lock#call
(gem) rack-1.5.2/lib/rack/lock.rb, line 17
ActionDispatch::Static#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/actionpack/lib/action_dispatch/middleware/static.rb, line 64
Fourpointohblog::Application#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/railties/lib/rails/engine.rb, line 511
Fourpointohblog::Application#call
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/railties/lib/rails/application.rb, line 96
Rack::ContentLength#call
(gem) rack-1.5.2/lib/rack/content_length.rb, line 14
block in Thin::Connection#pre_process
(gem) thin-1.5.0/lib/thin/connection.rb, line 81
Thin::Connection#pre_process
(gem) thin-1.5.0/lib/thin/connection.rb, line 79
Thin::Connection#process
(gem) thin-1.5.0/lib/thin/connection.rb, line 54
Thin::Connection#receive_data
(gem) thin-1.5.0/lib/thin/connection.rb, line 39
EventMachine.run
(gem) eventmachine-1.0.3/lib/eventmachine.rb, line 187
Thin::Backends::TcpServer#start
(gem) thin-1.5.0/lib/thin/backends/base.rb, line 63
Thin::Server#start
(gem) thin-1.5.0/lib/thin/server.rb, line 159
Rack::Handler::Thin.run
(gem) rack-1.5.2/lib/rack/handler/thin.rb, line 16
Rails::Server#start
(gem) rack-1.5.2/lib/rack/server.rb, line 264
Rails::Server#start
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/railties/lib/rails/commands/server.rb, line 83
block in <top (required)>
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/railties/lib/rails/commands.rb, line 80
<top (required)>
/home/user/.rvm/gems/ruby-1.9.3-p194/bundler/gems/rails-8744632fb564/railties/lib/rails/commands.rb, line 75
<main>
script/rails, line 6
<main>
script/rails, line 0
我试过调用下面的方法,但没有用
@comment.save!
@comment.save(@comment)
为什么会导致这个问题。
最佳答案
在 ActiveRecord
模型中不能有名为 attribute
的列,因为 attribute
是 ActiveRecord 中的私有(private)方法: :基
类。
将您的列名称更改为其他内容,它将起作用。
关于ruby-on-rails - ActiveRecord::Save 的参数数量错误(0 代表 1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15725707/
sanitize 是什么意思在 Rails 中是什么意思? 我正在阅读 CanCanCan 的文档.它说: When using strong_parameters or Rails 4+, you
在过去的几个月里,我感觉自己对 Ruby on Rails (RoR) 开发的了解达到了极限。我为大/小客户和 friend /爱好项目开发了大大小小的应用程序。我知道如何开发这些应用程序,但开始感觉
我昨天参加了一个关于扩展 Rails 的聚会,其中一个主题是 Hexagonal Rails。然而,我只做了一年的 Rails,对 MVC 结构非常满意(也许太舒服了),所以我不太了解适配器和消息队列
我使用多个 Rails 应用程序,一些在 Rails 3.2/Ruby 2.0 上,一些在 Rails 2.3/Ruby 1.8.7 上。 他们的共同点是,随着他们的成长和添加更多的依赖项/ gem
这个问题在这里已经有了答案: Using Rails-UJS in JS modules (Rails 6 with webpacker) (5 个答案) 关闭 3 年前。 我正在尝试使用 UJS
我正在开发一个当前使用 Rails 1.2 的 Rails 应用程序,所以我现在离最新的稳定版本(Rails 2.3)还有很长的路要走。 我应该如何进行迁移到更新版本的 Rails 的过程? 我应该一
尝试按照 Ryan Bates Backbone.js 教程构建抽奖应用程序,但我已经遇到了第一段代码的问题。在 application.js 的 init 函数中,他初始化了 Raffler 路由的
我正在使用 Rails 3.2 并且我有一个数据库表,我想在其中找到符合以下条件的所有行: a = true and b = true and ( 0 true, :b =>
我有一个用户类和一个联系人,其中联系人是用户的子类。这两个类都存储在用户表中。 我的联系人可能有也可能没有电子邮件地址,而我的用户需要一个电子邮件地址(我的用户模型定义中有 validates_pre
我正在编写一个教程,我在其中演示了一些 rails 命令。在我的机器上 rails和 script/rails两者都同样有效。有“首选”形式吗?两者中哪一个更普遍? 最佳答案 当您运行 rails 时
我正在寻找有关通过我的应用程序前进的最佳方式的建议,这是我首次开始集成Elasticsearch。我是一名初学者,但是热衷于深入研究,以便原谅任何明显的错误! 我遵循了http://www.sitep
我刚刚用 Rails new 启动了一个新的 Rails 应用程序,将默认数据库设置更改为 PostgresSQL。我用 bin/rails s 启动服务器,结果很奇怪 2016-04-21 05:0
我收到一个参数并希望它是这样的字符串: "abc,efg" 或者像这样的数组 ["abc","efg"] 在第一种情况下,我想将它转换成一个数组,什么是好的方法? 这是我的想法 if params[:
我刚刚用 Rails new 启动了一个新的 Rails 应用程序,将默认数据库设置更改为 PostgresSQL。我用 bin/rails s 启动服务器,结果很奇怪 2016-04-21 05:0
我收到一个参数并希望它是这样的字符串: "abc,efg" 或者像这样的数组 ["abc","efg"] 在第一种情况下,我想将它转换成一个数组,什么是好的方法? 这是我的想法 if params[:
我有 Rails 4,这是我的默认版本(我仍然希望它是)。但我不想在我的电脑上添加 rails 3.2。在以下命令中:gem install rails -v 3.2.16 我有这个警告: railt
您好,我想使用 Sheevaplug 构建一个“Rails Brick”来自 Marvell(操作系统是开箱即用的 Ubuntu,但您可以在其上安装其他发行版)。它将成为家庭服务器和静音、低成本(99
我需要能够从 Rails 控制台发送我的 Rails 应用程序的 Postgres 数据库中所有未接受的邀请。 (我有一个名为 Invitations 的表,其中包含一个名为 accepted 的 b
validate :cannot_modify_if_locked, on: :update def cannot_modify_if_locked if self.locked erro
我正在学习教程(学习 Rails 播客),需要更改以下路由语法,以便它与 Rails 3.0 兼容。谁能帮忙? map.view_page ':name', :controller => 'viewe
我是一名优秀的程序员,十分优秀!