1

在我的 Rails 应用程序中,我收到以下错误:

NameError in ProjectsController#index
app/controllers/projects_controller.rb:6:in `index'

我的路线如下所示:

RailsStarter::Application.routes.draw do
resources :projects

root :to => 'pages#home'
match '/' => 'pages#home'
match '/overview' => 'pages#overview'
match '/recruitmentInfo' => 'pages#recruitmentInfo'

和问题控制器:

 class ProjectsController < ApplicationController

 # GET /projects
 # GET /projects.json
 def index
 @projects = ::Project.all

 respond_to do |format|
   format.html # index.html.erb
   format.json { render json: @projects }
 end
end

到目前为止,我的调查表明它Project尚未初始化,但这无关紧要,因为它是一个构造函数,在它自己的类中。我什至尝试通过将此行添加config.autoload_paths += %W( #{config.root}/app/controllers)application.rb. 似乎还没有任何效果。任何想法将不胜感激。谢谢!

4

1 回答 1

0

[解决了]:

1 Reboot machine - the command must interfere with another server process
2 Check active_support gem versions by running `gem list` and remove them all
3 Remove `Gemfile.lock`
3 Run `bundle install` - this will add back your new version of gemfile
4 Run `rails generate model Project` again

现在应该解决这个问题!

于 2016-10-29T17:52:41.997 回答