我正在创建一个插件来识别移动设备请求。任何调用is_mobile_aware的控制器都应该具有适用于所有操作的“.html”和“.mobile”模板。现在我只是测试我的代码。我试图让每个请求都使用'.mobile'模板,但是当我发出请求时我收到错误。这是代码,错误如下:
代码:
module ActionController module MobileAware def self.included(base) base.extend(ClassMethods) end module ClassMethods def is_mobile_aware include ActionController::MobileAware::InstanceMethods before_filter :set_format end end module InstanceMethods def set_format request.format = :mobile end end end end
错误
nil的未定义方法`to_sym':NilClass
请求
参数:
{ “格式化”=> “中移动”}
感谢您的帮助!
完整追踪:
activesupport (3.0.3) lib/active_support/whiny_nil.rb:48:in `method_missing' actionpack (3.0.3) lib/action_controller/metal/rendering.rb:10:in `block in process_action' actionpack (3.0.3) lib/action_controller/metal/rendering.rb:10:in `map' actionpack (3.0.3) lib/action_controller/metal/rendering.rb:10:in `process_action' actionpack (3.0.3) lib/abstract_controller/callbacks.rb:18:in `block in process_action' activesupport (3.0.3) lib/active_support/callbacks.rb:450:in `_run__233835139__process_action__997034143__callbacks' activesupport (3.0.3) lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks' activesupport (3.0.3) lib/active_support/callbacks.rb:93:in `run_callbacks' actionpack (3.0.3) lib/abstract_controller/callbacks.rb:17:in `process_action' actionpack (3.0.3) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action' activesupport (3.0.3) lib/active_support/notifications.rb:52:in `block in instrument' activesupport (3.0.3) lib/active_support/notifications/instrumenter.rb:21:in `instrument' activesupport (3.0.3) lib/active_support/notifications.rb:52:in `instrument' actionpack (3.0.3) lib/action_controller/metal/instrumentation.rb:29:in `process_action' actionpack (3.0.3) lib/action_controller/metal/rescue.rb:17:in `process_action' actionpack (3.0.3) lib/abstract_controller/base.rb:120:in `process' actionpack (3.0.3) lib/abstract_controller/rendering.rb:40:in `process' actionpack (3.0.3) lib/action_controller/metal.rb:138:in `dispatch' actionpack (3.0.3) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch' actionpack (3.0.3) lib/action_controller/metal.rb:178:in `block in action' actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:62:in `call' actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:62:in `dispatch' actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:27:in `call' rack-mount (0.6.13) lib/rack/mount/route_set.rb:148:in `block in call' rack-mount (0.6.13) lib/rack/mount/code_generation.rb:93:in `block in recognize' rack-mount (0.6.13) lib/rack/mount/code_generation.rb:75:in `optimized_each' rack-mount (0.6.13) lib/rack/mount/code_generation.rb:92:in `recognize' rack-mount (0.6.13) lib/rack/mount/route_set.rb:139:in `call' actionpack (3.0.3) lib/action_dispatch/routing/route_set.rb:492:in `call' hoptoad_notifier (2.4.4) lib/hoptoad_notifier/rack.rb:27:in `call' haml (3.0.25) lib/sass/plugin/rack.rb:41:in `call' actionpack (3.0.3) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call' actionpack (3.0.3) lib/action_dispatch/middleware/head.rb:14:in `call' rack (1.2.1) lib/rack/methodoverride.rb:24:in `call' actionpack (3.0.3) lib/action_dispatch/middleware/params_parser.rb:21:in `call' actionpack (3.0.3) lib/action_dispatch/middleware/flash.rb:182:in `call' actionpack (3.0.3) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call' actionpack (3.0.3) lib/action_dispatch/middleware/cookies.rb:295:in `call' activerecord (3.0.3) lib/active_record/query_cache.rb:32:in `block in call' activerecord (3.0.3) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache' activerecord (3.0.3) lib/active_record/query_cache.rb:12:in `cache' activerecord (3.0.3) lib/active_record/query_cache.rb:31:in `call' activerecord (3.0.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:353:in `call' actionpack (3.0.3) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call' activesupport (3.0.3) lib/active_support/callbacks.rb:415:in `_run_call_callbacks' actionpack (3.0.3) lib/action_dispatch/middleware/callbacks.rb:44:in `call' rack (1.2.1) lib/rack/sendfile.rb:107:in `call' actionpack (3.0.3) lib/action_dispatch/middleware/remote_ip.rb:48:in `call' actionpack (3.0.3) lib/action_dispatch/middleware/show_exceptions.rb:46:in `call' railties (3.0.3) lib/rails/rack/logger.rb:13:in `call' rack (1.2.1) lib/rack/runtime.rb:17:in `call' activesupport (3.0.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call' hoptoad_notifier (2.4.4) lib/hoptoad_notifier/user_informer.rb:12:in `call' rack (1.2.1) lib/rack/lock.rb:11:in `block in call' :10:in `synchronize' rack (1.2.1) lib/rack/lock.rb:11:in `call' actionpack (3.0.3) lib/action_dispatch/middleware/static.rb:30:in `call' railties (3.0.3) lib/rails/application.rb:168:in `call' railties (3.0.3) lib/rails/application.rb:77:in `method_missing' railties (3.0.3) lib/rails/rack/log_tailer.rb:14:in `call' rack (1.2.1) lib/rack/content_length.rb:13:in `call' rack (1.2.1) lib/rack/handler/webrick.rb:52:in `service' C:/Ruby192/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service' C:/Ruby192/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run' C:/Ruby192/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'