Ruby 1.8.7 中的 NoMethodError
我开始开发一个名为 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
Ive started working on an application called Shapado (http://shapado.com) which is running on Ruby with a mongo database in the background. Im getting the following error when I try to add some data to the database. I have attached all the relevant files that I think could be the source.
The error
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'
tags_for_autocomplete method in QuestionsController.rb
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将代码中 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
这似乎为我工作。
Replace "current_group.questions.find_tags" with "Question.find_tags" in the 2 locations in code.
As mentioned here:
http://shapado.com/questions/what-is-the-cause-of-the-nomethoderror-when-using-the-search-box-on-the-tags-page
This seems to work for me.