gpt4 book ai didi

ruby - Ruby 1.8.7 中的 NoMethodError

转载 作者:太空宇宙 更新时间:2023-11-03 16:57:46 24 4
gpt4 key购买 nike

我开始开发一个名为 Shapado (http://shapado.com) 的应用程序,该应用程序在 Ruby 上运行,后台有一个 mongo 数据库。当我尝试向数据库添加一些数据时出现以下错误。我已附上所有我认为可能是来源的相关文件。

错误

Processing QuestionsController#tags_for_autocomplete to js (for 93.97.246.67 at 2011-03-31 10:02:00) [GET]
Parameters: {"tag"=>"backup"}

NoMethodError (undefined method `find_tags' for #<Array:0x7f24f1032448>):
/var/lib/gems/1.8/gems/mongo_mapper-0.8.6/lib/mongo_mapper/plugins/associations/proxy.rb:109:in `send'
/var/lib/gems/1.8/gems/mongo_mapper-0.8.6/lib/mongo_mapper/plugins/associations/proxy.rb:109:in `method_missing'
/var/lib/gems/1.8/gems/mongo_mapper-0.8.6/lib/mongo_mapper/plugins/dynamic_querying.rb:37:in `method_missing'
/var/lib/gems/1.8/gems/mongo_mapper-0.8.6/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb:76:in `method_missing'
app/controllers/questions_controller.rb:184:in `tags_for_autocomplete'
app/controllers/questions_controller.rb:180:in `tags_for_autocomplete'
compass (0.10.5) lib/compass/app_integration/rails/actionpack2/action_controller.rb:7:in `process'
warden (1.0.3) lib/warden/manager.rb:35:in `call'
warden (1.0.3) lib/warden/manager.rb:35:in `call'
warden (1.0.3) lib/warden/manager.rb:34:in `catch'
warden (1.0.3) lib/warden/manager.rb:34:in `call'
haml (3.0.25) lib/sass/plugin/rack.rb:41:in `call'
/var/lib/gems/1.8/gems/mongomapper_ext-0.5.0/lib/mongomapper_ext/file_server.rb:17:in `call'
app/middlewares/dynamic_domain.rb:17:in `call'
app/middlewares/mongo_mapper_middleware.rb:24:in `call'
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'

QuestionsController.rb 中的 tags_for_autocomplete 方法

def tags_for_autocomplete   
respond_to do |format|
format.js do
result = []
if q = params[:tag]
result = current_group.questions.find_tags(/^#{Regexp.escape(q.downcase)}/i,
:group_id => current_group.id,
:banned => false)
end
results = result.map do |t|
{:caption => "#{t["name"]} (#{t["count"].to_i})", :value => t["name"]}
end
# if no results, show default tags
if results.empty?
results = current_group.default_tags.map {|tag|{:value=> tag, :caption => tag}}
end
render :json => results
end
end

/var/lib/gems/1.8/gems/mongo_mapper-0.8.6/lib/mongo_mapper/plugins/associations/proxy.rb:109

protected
def method_missing(method, *args, &block)
if load_target
target.send(method, *args, &block)
end
end

最佳答案

将代码中 2 个位置的“current_group.questions.find_tags”替换为“Question.find_tags”。

正如这里提到的: http://shapado.com/questions/what-is-the-cause-of-the-nomethoderror-when-using-the-search-box-on-the-tags-page

这似乎对我有用。

关于ruby - Ruby 1.8.7 中的 NoMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5498648/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com