0

我当然为此而失去理智/睡眠。这是我的 questions_controller.rb

class QuestionsController < ApplicationController
  # GET /questions
  # GET /questions.json
  def index
    @questions = Question.all

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

这是我的 applications_controller.rb

class ApplicationController < ActionController::Base
  protect_from_forgery
end

这是我的 rake 路线:

    questions GET    /questions(.:format)          questions#index
              POST   /questions(.:format)          questions#create
 new_question GET    /questions/new(.:format)      questions#new
edit_question GET    /questions/:id/edit(.:format) questions#edit
     question GET    /questions/:id(.:format)      questions#show
              PUT    /questions/:id(.:format)      questions#update
              DELETE /questions/:id(.:format)      questions#destroy
   home_index GET    /home/index(.:format)         home#index

这是我的路线.rb

App::Application.routes.draw do
  resources :questions
end

前往时出错http://0.0.0.0:3000/questions

uninitialized constant QuestionsController

可能是什么错误?

4

2 回答 2

1

当一个文件中存在语法错误时,有时会发生这种错误。重新启动您的开发服务器并在其输出中查找错误。

特别是检查线

format.html # index.html.erb

我不认为它可以这样写。

于 2012-05-01T17:09:01.870 回答
0

你能确保控制器文件名的复数形式正确吗?

app/controllers/questions_controller.rb

谢谢。

于 2012-05-02T00:54:35.493 回答