未定义的局部变量或方法名称“项目名称”对于主要:对象

发布于 2024-11-19 03:08:47 字数 9165 浏览 0 评论 0原文

好吧,我在启动 Rails 服务器以及运行任何 rake 命令时遇到了一些问题,因为它因未定义的本地变量或方法名称“Newventureclub”(这是我的项目的名称)而失败。在运行几次迁移并向我的路由文件添加一些路径后,这个错误开始发生,但即使向后退一步,我似乎也无法让它再次工作。运行 --trace 我得到这个:

/Users/mbs89/webdev/nvc/newventureclub/config/routes.rb:1
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load'
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load'
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596:in `new_constants_in'
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:127:in `reload_routes!'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:127:in `each'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:127:in `reload_routes!'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:120:in `routes_reloader'
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/file_update_checker.rb:32:in `call'
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/file_update_checker.rb:32:in `execute_if_updated'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application/finisher.rb:51
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application/finisher.rb:52:in `call'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application/finisher.rb:52
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `instance_exec'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `run'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:50:in `run_initializers'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `each'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `run_initializers'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:134:in `initialize!'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:77:in `send'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:77:in `method_missing'
/Users/mbs89/webdev/nvc/newventureclub/config/environment.rb:5
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:103:in `require'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:103:in `require_environment!'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:216:in `initialize_tasks'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:205:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:158:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:176:in `invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:174:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:157:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:62:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/bin/rake:32
/usr/bin/rake:19:in `load'
/usr/bin/rake:19

当我尝试启动服务器时,我收到略有不同的错误消息:

undefined local variable or method `Newventureclub' for main:Object (NameError)
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596:in `new_constants_in'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:127:in `reload_routes!'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:127:in `each'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:127:in `reload_routes!'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:120:in `routes_reloader'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/file_update_checker.rb:32:in `call'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/file_update_checker.rb:32:in `execute_if_updated'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application/finisher.rb:51
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application/finisher.rb:52:in `call'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application/finisher.rb:52
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `instance_exec'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `run'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:50:in `run_initializers'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `each'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `run_initializers'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:134:in `initialize!'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:77:in `send'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:77:in `method_missing'
    from /Users/mbs89/webdev/nvc/newventureclub/config/environment.rb:5
    from /Users/mbs89/webdev/nvc/newventureclub/config.ru:3:in `require'
    from /Users/mbs89/webdev/nvc/newventureclub/config.ru:3
    from /Library/Ruby/Gems/1.8/gems/rack-1.2.3/lib/rack/builder.rb:46:in `instance_eval'
    from /Library/Ruby/Gems/1.8/gems/rack-1.2.3/lib/rack/builder.rb:46:in `initialize'
    from /Users/mbs89/webdev/nvc/newventureclub/config.ru:1:in `new'
    from /Users/mbs89/webdev/nvc/newventureclub/config.ru:1

这是我的路由文件,我认为它导致了错误,但我无法发现它:

Newventureclub::Application.routes.draw do

  resources :list_locations

  resources :list_controls

  resources :companies  
  get "all_members" => "main#members", :as => "all_members"

  get "org_chart" => "main#orgchart", :as => "org_chart"
  get "all_investments" => "main#investments", :as => "all_investments"
  get "all_memories" => "main#memories", :as => "all_memories"
  get "all_retreats" => "main#retreats", :as => "all_retreats"
  get "calendar" => "main#calendar", :as => "calendar"
  get "log_out" => "sessions#destroy", :as => "log_out"
  get "log_in" => "sessions#new", :as => "log_in"
  get "sign_up" => "members#new", :as => "sign_up"

  resources :members

  resources :sessions

  root :to => "sessions#new"

编辑这里是我的环境.rb文件:

 # Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
Newventureclub::Application.initialize!

EDIT2:这是我的application.rb 取出所有注释

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

require 'rails/all'


Bundler.require(:default, Rails.env) if defined?(Bundler)

module Newventureclub
  class Application < Rails::Application

    config.encoding = "utf-8"

    config.filter_parameters += [:password]
  end
end

Ok so I'm having some issues with starting the rails server as well as running any rake commands as it fails out with an undefined local variable or method name 'Newventureclub' (which is the name of my project). This error started happening after running a couple migration and adding some paths to my routes file, but even stepping backward I can't seem to get it to work again. Running --trace I get this:

/Users/mbs89/webdev/nvc/newventureclub/config/routes.rb:1
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load'
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load'
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596:in `new_constants_in'
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:127:in `reload_routes!'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:127:in `each'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:127:in `reload_routes!'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:120:in `routes_reloader'
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/file_update_checker.rb:32:in `call'
/Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/file_update_checker.rb:32:in `execute_if_updated'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application/finisher.rb:51
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application/finisher.rb:52:in `call'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application/finisher.rb:52
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `instance_exec'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `run'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:50:in `run_initializers'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `each'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `run_initializers'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:134:in `initialize!'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:77:in `send'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:77:in `method_missing'
/Users/mbs89/webdev/nvc/newventureclub/config/environment.rb:5
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:103:in `require'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:103:in `require_environment!'
/Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:216:in `initialize_tasks'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:205:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:158:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:176:in `invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:174:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:157:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:90:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:62:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.9.2/bin/rake:32
/usr/bin/rake:19:in `load'
/usr/bin/rake:19

When I try to start the server I get a slightly different error message:

undefined local variable or method `Newventureclub' for main:Object (NameError)
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596:in `new_constants_in'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:127:in `reload_routes!'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:127:in `each'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:127:in `reload_routes!'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:120:in `routes_reloader'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/file_update_checker.rb:32:in `call'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.0.3/lib/active_support/file_update_checker.rb:32:in `execute_if_updated'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application/finisher.rb:51
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application/finisher.rb:52:in `call'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application/finisher.rb:52
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `instance_exec'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `run'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:50:in `run_initializers'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `each'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `run_initializers'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:134:in `initialize!'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:77:in `send'
    from /Library/Ruby/Gems/1.8/gems/railties-3.0.3/lib/rails/application.rb:77:in `method_missing'
    from /Users/mbs89/webdev/nvc/newventureclub/config/environment.rb:5
    from /Users/mbs89/webdev/nvc/newventureclub/config.ru:3:in `require'
    from /Users/mbs89/webdev/nvc/newventureclub/config.ru:3
    from /Library/Ruby/Gems/1.8/gems/rack-1.2.3/lib/rack/builder.rb:46:in `instance_eval'
    from /Library/Ruby/Gems/1.8/gems/rack-1.2.3/lib/rack/builder.rb:46:in `initialize'
    from /Users/mbs89/webdev/nvc/newventureclub/config.ru:1:in `new'
    from /Users/mbs89/webdev/nvc/newventureclub/config.ru:1

Here is my routes file which I think is causing the error but I can't spot it:

Newventureclub::Application.routes.draw do

  resources :list_locations

  resources :list_controls

  resources :companies  
  get "all_members" => "main#members", :as => "all_members"

  get "org_chart" => "main#orgchart", :as => "org_chart"
  get "all_investments" => "main#investments", :as => "all_investments"
  get "all_memories" => "main#memories", :as => "all_memories"
  get "all_retreats" => "main#retreats", :as => "all_retreats"
  get "calendar" => "main#calendar", :as => "calendar"
  get "log_out" => "sessions#destroy", :as => "log_out"
  get "log_in" => "sessions#new", :as => "log_in"
  get "sign_up" => "members#new", :as => "sign_up"

  resources :members

  resources :sessions

  root :to => "sessions#new"

EDIT here is my environment.rb file:

 # Load the rails application
require File.expand_path('../application', __FILE__)

# Initialize the rails application
Newventureclub::Application.initialize!

EDIT2: Here is my application.rb took out all the comments

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

require 'rails/all'


Bundler.require(:default, Rails.env) if defined?(Bundler)

module Newventureclub
  class Application < Rails::Application

    config.encoding = "utf-8"

    config.filter_parameters += [:password]
  end
end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文