lxf_chn_1 2010-01-31 23:23
浏览 523
已采纳

(Ruby on rails) 错误“NoMethodError (undefined method `on' for #<Tag id:, name:>)”

安装了acts_as_taggable_on_steroids插件(ruby 1.8.6, rails 2.0.2),其中模型代码bookmark.rb包括:
def tag_with(tags) (bookmark.rb第27行)
Tag.transaction do
taggings.destroy_all
tags.each { |name| Tag.find_or_create_by_name(name).on(self) }

end
end

程序主要实现为网页添加标签,在运行时发生错误,其中log记录如下:
####################################################################################################
NoMethodError (undefined method on' for #<Tag id: 16, name: "good,god">):
C:/INSTAN~1.0-W/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/attribute_methods.rb:205:in
method_missing'
/app/models/bookmark.rb:29:in tag_with'
/app/models/bookmark.rb:29:in
each'
/app/models/bookmark.rb:29:in tag_with'
C:/INSTAN~1.0-W/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in
transaction'
C:/INSTAN~1.0-W/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:80:in transaction'
/app/models/bookmark.rb:27:in
tag_with'
/app/controllers/bookmarks_controller.rb:40:in `create'

####################################################################################################
在控制器bookmark_controller.rb中调用方法tag_with:

POST /users/{username}/bookmarks

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])
  if bookmark.save
    # Add tags.
    bookmark.tag_with(params[:taglist]) if params[:taglist]  (调用方法tag_with)

    # 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

  • 写回答

4条回答 默认 最新

  • weixin_42355801 2010-02-03 07:54
    关注

    我觉得你应该重新安装acts_as_taggable插件,毕竟它和acts_as_taggable_on_steroids插件有不少不同的地方。http://thegiive.iteye.com/blog/75716介绍如何使用插件acts_as_taggable。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?