我开始研究一个名为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
答案 0 :(得分:0)
将“current_group.questions.find_tags”替换为代码中2个位置的“Question.find_tags”。
这似乎对我有用。