【问题标题】:Rails 3 Routing Error uninitialized constant ApplicationController on Hello WorldRails 3路由错误未初始化常量ApplicationController在Hello World上
【发布时间】:2013-01-11 18:32:49
【问题描述】:

我在那儿。所以我是 Rails 3 的新手,试图执行一个简单的 hello world com 一个 sql lite db,但我一直得到一个

未初始化的常量 ApplicationController

我的路线是:

LoadTest::Application.routes.draw do

  match '/hello' => 'hello#hello' , :as => :hello
  match "/erb_sql" => "hello#hellodb", :as => :erb_sql

end

我的控制器:

class HelloController < ApplicationController
    def hello
        render :text => "Hello World!"
    end
    def hellodb
        @data = Hello.all
    end
end

和我的观点(hellodb.html.erb):

<table border="1">
        <% for row in @data %>
            <tr><td><%=h row.id %></td><td><%=h row.data %></td></tr>
        <% end %>
</table>

还有我的模特:

class Hello < ActiveRecord::Base
end

我该如何解决这个问题?

【问题讨论】:

  • 你有application_controller.rb吗?
  • no.. 我应该在里面放什么?

标签: ruby-on-rails ruby-on-rails-3 routes


【解决方案1】:

您必须拥有application_controller.rb。这是基本的控制器,其他控制器都继承自它。

我不知道您是如何创建应用程序的,因为正确的方法是在控制台中运行 rails new application_name。包括application_controller.rb 在内的整个结构将在application_name 文件夹中创建。

【讨论】:

  • 我猜我不小心删除了那个文件。它现在正在工作。谢谢
猜你喜欢
  • 2011-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多