这真的很奇怪。我只是输入了
rails new website
使用以下命令创建控制器:
rails generate controller static home about index
当我去localhost:3000/static/home
时,我收到错误:
NoMethodError in StaticController#about
这是终端
中的错误日志NoMethodError (undefined method `_view_paths' for nil:NilClass):
actionview (4.1.5) lib/action_view/view_paths.rb:45:in `lookup_context'
actionview (4.1.5) lib/action_view/rendering.rb:29:in `process'
actionpack (4.1.5) lib/action_controller/metal.rb:196:in `dispatch'
actionpack (4.1.5) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.1.5) lib/action_controller/metal.rb:232:in `block in action'
actionpack (4.1.5) lib/action_dispatch/routing/route_set.rb:82:in `call'
actionpack (4.1.5) lib/action_dispatch/routing/route_set.rb:82:in `dispatch'
actionpack (4.1.5) lib/action_dispatch/routing/route_set.rb:50:in `call'
actionpack (4.1.5) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.1.5) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.1.5) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.1.5) lib/action_dispatch/routing/route_set.rb:678:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.1.5) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.1.5) lib/action_dispatch/middleware/flash.rb:254:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.1.5) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.1.5) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.1.5) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
activerecord (4.1.5) lib/active_record/migration.rb:380:in `call'
actionpack (4.1.5) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.1.5) lib/active_support/callbacks.rb:82:in `run_callbacks'
actionpack (4.1.5) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.1.5) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.1.5) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.1.5) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.1.5) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.1.5) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.1.5) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.1.5) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.1.5) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.1.5) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.1.5) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.1.5) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.1.5) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.1.5) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.1.5) lib/rails/engine.rb:514:in `call'
railties (4.1.5) lib/rails/application.rb:144:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/Users/Yitao/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/Users/Yitao/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/Users/Yitao/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
我在rake路线下得到这个
Prefix Verb URI Pattern Controller#Action
static_home GET /static/home(.:format) static#home
static_about GET /static/about(.:format) static#about
static_class GET /static/class(.:format) static#class
static_contact GET /static/contact(.:format) static#contact
static_index GET /static/index(.:format) static#index
static_instructors GET /static/instructors(.:format) static#instructors
static_testimonial GET /static/testimonial(.:format) static#testimonial
此外,所有观点都已创建。通过控制器,路线和视图,我不知道为什么事情还没有工作。
控制器代码:
class StaticController < ApplicationController
def home
end
def about
end
def class
end
def contact
end
def index
end
def instructors
end
def testimonial
end
end
非常感谢任何帮助!