weixin_42355801 2010-01-09 15:48
浏览 960
已采纳

(Ruby on rails) 错误“ArgumentError (wrong number of arguments (1 for 0))”如何解决

是因为我没有安装'digest/sha1'和'digest/md5'么?当代码中有如下语句,需要安装这几个文件么?谢谢各位的帮助!
require 'digest/sha1'
require 'digest/md5'
require 'rubygems'
require 'atom/feed'

#################################################################################################
运行时出现错误500 internal erro,log记录如下:
/app/models/bookmark.rb:20:in initialize'
/app/models/bookmark.rb:20:in
new'
/app/models/bookmark.rb:20:in uri='
C:/INSTAN~1.0-W/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:2117:in
send'
C:/INSTAN~1.0-W/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:2117:in attributes='
C:/INSTAN~1.0-W/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:2116:in
each'
C:/INSTAN~1.0-W/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:2116:in attributes='
C:/INSTAN~1.0-W/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:1926:in
initialize'
/app/controllers/bookmarks_controller.rb:37:in new'
/app/controllers/bookmarks_controller.rb:37:in
create'
C:/INSTAN~1.0-W/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `send'
#################################################################################################
我在模型Bookmark.rb中有如下定义:
def uri=(new_uri)
super
self.uri_hash = Digest::MD5.new(new_uri).to_s (第20行)
end
#################################################################################################
bookmarks_controller代码片断如下:
def create
bookmark = Bookmark.find_by_user_id_and_uri(params[:bookmark][:user_id],
params[:bookmark][:uri])
if bookmark
# This user has already bookmarked this URI. They should be
# using PUT instead.
headers['Location'] = bookmark_url(@user.name, bookmark.uri)
render :nothing => true, :status => "409 Conflict"
else
# Enforce default values for 'timestamp' and 'public'
params[:bookmark][:timestamp] ||= Time.now
params[:bookmark][:public] ||= "1"

  # Create the bookmark in the database.
  bookmark = Bookmark.new(params[:bookmark]) (第37行)
  if bookmark.save
    # Add tags.
    bookmark.tag_with(params[:taglist]) if params[:taglist]

    # Send a 201 response code that points to the location of the
    # new bookmark.
    headers['Location'] = bookmark_url(@user.name, bookmark.uri)
    render :nothing => true, :status => "201 Created"
  else
    render :xml => bookmark.errors.to_xml, :status => "400 Bad Request"
  end
end

end

  • 写回答

1条回答 默认 最新

  • Hooopo 2010-01-09 17:28
    关注

    ArgumentError (wrong number of arguments (1 for 0)的意思是你参数传的不正确,本来该不传参数的。结果你给传入了一个参数。
    就是这个地方:Digest::MD5.new
    这个new方法是不用参数的。。。去掉就可以,去查查MD5的用法。。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c