简体   繁体   English

Rails和mysql DB堆栈级别太深

[英]Rails and mysql DB stack level too deep

I am learning ror and in my controller I am trying to access the tests table. 我正在学习ror,并且在我的控制器中尝试访问测试表。 Here is the code in my controller 这是我控制器中的代码

class ExecutionsController < ApplicationController
    def index
        @testcases = Tests.all
    end
end

Here is my view 这是我的看法

<h1>Hello, Wortld!</h1>
<hr />
<% @testcases.each do |t| %>
    <p><%= t.package %></p>
<% end %>

When I run the server and try to load the page I get an error page that talks about the stack being too long. 当我运行服务器并尝试加载该页面时,我得到一个错误页面,该页面谈论堆栈太长。 If I load up the rails console, I can see the tests database is there but for the life of me I cannot get my webapp to talk to it. 如果我加载了Rails控制台,我可以看到测试数据库在那里,但是在我的生命中,我无法让我的Web应用程序与之对话。

➜  automation_metrics_tool git:(master) ✗ rails c
Loading development environment (Rails 4.1.0.rc1)
2.1.1 :001 > ActiveRecord::Base.connection.tables
=> ["execution_notes", "jira_defects", "requirements", "schema_migrations",    
"store_environments", "stores", "test_executions", "test_requirements", "test_types",    
"testexec_jiradefects", "tests", "zephyr_testcases"] 

Thanks for any help. 谢谢你的帮助。

In Rails names of the ActiveRecord models are in singular while the real tables in the database are in plural. 在Rails中,ActiveRecord模型的名称为单数,而数据库中的实际表为复数。 So in your example you should call User.all instead of Users.all . 因此,在您的示例中,应调用User.all而不是Users.all

I figured out the problem. 我解决了这个问题。 I had one of the table fields called class. 我有一个称为类的表字段之一。 Soon as I changed my model from class to clazz, re-imported db, everything was good. 当我将模型从类更改为clazz,重新导入db时,一切都很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM