rails s命令错误

时间:2012-09-08 16:28:43

标签: ruby-on-rails

当我发出命令rails s时,会出现以下错误消息:

  nathan@Nathan-Ubuntu:~/Documents/Aptana Studio 3 Workspace/sample_application/app/controllers$ rails s
=> Booting WEBrick
=> Rails 3.2.8 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/home/nathan/Documents/Aptana Studio 3 Workspace/sample_application/config/routes.rb:1:in `<top (required)>': uninitialized constant SampleApp (Name
Error)
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/application/routes_reloader.rb:40:in `each'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/application/routes_reloader.rb:40:in `load_paths'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/application/routes_reloader.rb:16:in `reload!'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/application/routes_reloader.rb:26:in `block in updater'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/file_update_checker.rb:78:in `call'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/file_update_checker.rb:78:in `execute'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/application/routes_reloader.rb:27:in `updater'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/application/finisher.rb:66:in `block in <module:Finisher>'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `instance_exec'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/initializable.rb:30:in `run'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/initializable.rb:55:in `block in run_initializers'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `each'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/initializable.rb:54:in `run_initializers'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/application.rb:136:in `initialize!'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/railtie/configurable.rb:30:in `method_missing'
        from /home/nathan/Documents/Aptana Studio 3 Workspace/sample_application/config/environment.rb:5:in `<top (required)>'
        from /home/nathan/Documents/Aptana Studio 3 Workspace/sample_application/config.ru:4:in `require'
        from /home/nathan/Documents/Aptana Studio 3 Workspace/sample_application/config.ru:4:in `block in <main>'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
        from /home/nathan/Documents/Aptana Studio 3 Workspace/sample_application/config.ru:1:in `new'
        from /home/nathan/Documents/Aptana Studio 3 Workspace/sample_application/config.ru:1:in `<main>'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/server.rb:200:in `app'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands/server.rb:46:in `app'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/server.rb:252:in `start'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands/server.rb:70:in `start'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:55:in `block in <top (required)>'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:50:in `tap'
        from /home/nathan/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.8/lib/rails/commands.rb:50:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'

的routes.rb

SampleApp::Application.routes.draw do
  get "static_pages/home"
  get "static_pages/help"
end

配置/ application.rb中

require File.expand_path('../boot', __FILE__)

require 'rails/all'

if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  Bundler.require(*Rails.groups(:assets => %w(development test)))
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)
end

module SampleApplication
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Custom directories with classes and modules you want to be autoloadable.
    # config.autoload_paths += %W(#{config.root}/extras)

    # Only load the plugins named here, in the order given (default is alphabetical).
    # :all can be used as a placeholder for all plugins not explicitly named.
    # config.plugins = [ :exception_notification, :ssl_requirement, :all ]

    # Activate observers that should always be running.
    # config.active_record.observers = :cacher, :garbage_collector, :forum_observer

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    # config.time_zone = 'Central Time (US & Canada)'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de

    # Configure the default encoding used in templates for Ruby 1.9.
    config.encoding = "utf-8"

    # Configure sensitive parameters which will be filtered from the log file.
    config.filter_parameters += [:password]

    # Enable escaping HTML in JSON.
    config.active_support.escape_html_entities_in_json = true

    # Use SQL instead of Active Record's schema dumper when creating the database.
    # This is necessary if your schema can't be completely dumped by the schema dumper,
    # like if you have constraints or database-specific column types
    # config.active_record.schema_format = :sql

    # Enforce whitelist mode for mass assignment.
    # This will create an empty whitelist of attributes available for mass-assignment for all models
    # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
    # parameters by using an attr_accessible or attr_protected declaration.
    config.active_record.whitelist_attributes = true

    # Enable the asset pipeline
    config.assets.enabled = true

    # Version of your assets, change this if you want to expire all your assets
    config.assets.version = '1.0'
  end
end

2 个答案:

答案 0 :(得分:0)

更新:检查路线后

SampleApp更改为SampleApplication

如果应用

,请查看您的traceapplication path名称

sample_application因此应用名称应为SampleApplication

但是从跟踪看来,你似乎将它作为SampleApp

这可能是因为您稍后重命名了该应用

在学习的同时从一些教程中做了一些复制粘贴。

检查config/envirnoment.rb文件,最后一行应包含应用程序名称

类似

SampleApplication::Application.initialize 

所以示例中的应用程序名称为SampleApplication

答案 1 :(得分:0)

您的config/routes.rb应以SampleApplication::Application.routes.draw do

开头