简体   繁体   English

Ruby on Rails-在f.label上完成了500个内部错误

[英]Ruby on Rails - Completed 500 internal error on f.label

EDIT 编辑

Here's the project on GitHub: https://github.com/lionelrudaz/myteam2 这是GitHub上的项目: https : //github.com/lionelrudaz/myteam2


I'm making my first application in Ruby on Rails by using the template on Railsapp (Twitter Bootstrap, Devise and CanCan). 我正在通过使用Railsapp上的模板(Twitter Bootstrap,Devise和CanCan)在Ruby on Rails中创建我的第一个应用程序。

I've also made the necessary steps to publish my app to Heroku. 我还采取了必要步骤将我的应用发布到Heroku。

Everything went fine so far, first publication on Heroku was alright, until I restarted the server on my MacBook Pro. 到目前为止一切都很好,在Heroku上的第一本出版物都还不错,直到我在MacBook Pro上重新启动服务器为止。

Now I get always the default error page with message "We're sorry, but something went wrong." 现在,我总是得到默认错误页面,并显示消息“很抱歉,出了点问题。”

In the terminal, I get: 在终端中,我得到:

=> Booting Thin
=> Rails 3.2.8 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
>> Thin web server (v1.5.0 codename Knife)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop


Started GET "/" for 127.0.0.1 at 2012-10-01 19:19:21 +0200
Processing by HomeController#index as HTML
     User Load (0.3ms)  SELECT "users".* FROM "users" 
     Club Load (0.2ms)  SELECT "clubs".* FROM "clubs" ORDER BY "clubs"."id" DESC LIMIT 1
Rendered home/index.html.erb within layouts/application (23.2ms)
Completed 500 Internal Server Error in 190ms

Since I don't know how to disable the error page to get a real stack trace, I've started to remove lines of code by lines of code to find which line isn't working. 由于我不知道如何禁用错误页面来获取真实的堆栈跟踪,因此我开始逐行删除代码行,以查找哪一行行不通。 Actually, it looks like the f.label instructions aren't working anymore. 实际上,看起来f.label指令不再起作用。 I know they did, I've used my app for a long time. 我知道他们做到了,我已经使用我的应用很长时间了。

Here's my home_controller.rb file 这是我的home_controller.rb文件

class HomeController < ApplicationController
  def index
    @users = User.all
    @club = Club.last
  end
end

index.html.erb index.html.erb

<h3>Home</h3>

<%= debug @club %>

<%= form_for @club do |f| %>

  <div class="control-group">
    <%= RUBY_VERSION %>
    <%= Rails.version %>
    <%= f.label :name, :name %>
    <%= f.text_field :name %>
  </div>

 <% end %>

 <% @users.each do |user| %>
    <p>User: <%=link_to user.name, user %></p>
 <% end %>

The error is fired when I change 我更改时会触发错误

 <%= f.label :name, :name %>

to

 <%= f.label :name %>

I updated my app on Heroku so you can check the debug: http://myteam2.herokuapp.com/ 我在Heroku上更新了我的应用程序,因此您可以检查调试: http : //myteam2.herokuapp.com/

I don't know what's wrong, it's so basic that I feel so dumb. 我不知道出什么问题了,这太基础了,我觉得自己很傻。

When I was investigating, I've remarked that the second argument of f.label must be a String. 在调查时,我已经指出f.label的第二个参数必须是String。 It's impossible to use the t() method to change the text of the email from a i18n file. 无法使用t()方法从i18n文件更改电子邮件的文本。

I can't go ahead with my application and feel really frustrated. 我无法继续申请,感到非常沮丧。 My Google researches haven't been successful. 我的Google研究没有成功。

Let me know if you need more information. 如果您需要更多信息,请与我们联系。

Cheers, 干杯,

You're confusing using label with and without a form builder. 您在带有和不带有表单生成器的情况下使用label感到困惑。

When you use label inside of form_tag , it takes two parameters: the first is the name of the parameter required to connect the label to the appropriate text field, and the second is the actual label text. form_tag使用label时,它form_tag两个参数:第一个是将标签连接到适当的文本字段所需的参数名称,第二个是实际的标签文本。

However, when you use form_for @whatever do |f| 但是,当您使用form_for @whatever do |f| , the label's first parameter is automatically known, since you do f.label :name , and f knows what name is, and what f.text_field will generate, and does all the nastiness for you. ,标签的第一个参数会自动知道,因为您执行f.label :name ,并且f知道名称是什么, f.text_field将生成什么,并为您完成所有操作。

This is often not clear in the Rails documentation, but as a rule you can eliminate the first parameter of the form helper methods when you're doing them from an associated model using form_for . 这通常在Rails文档中并不清楚,但是通常,当您使用form_for从关联模型中进行操作时,可以消除表单帮助器方法的第一个参数。

Lionel, you should seen an error message when you are running your project locally with the development environment. Lionel,在开发环境中本地运行项目时,应该会看到一条错误消息。

I cloned your project and after a little setup I ran rails s to start the project with the default development environment. 我克隆了您的项目,并进行了一些设置后运行了rails s ,以使用默认开发环境启动该项目。 The home page loaded fine, but clicking "Login" to go to /users/sign_in showed the following error: 主页加载正常,但是单击“登录”转到/ users / sign_in显示以下错误:

Error: 错误:

http://www.evernote.com/shard/s157/sh/078d0a12-73b1-4eb7-9430-55b916f19ef7/12c0cbb7b7254e5c02bb7ff0f0c4aa3f http://www.evernote.com/shard/s157/sh/078d0a12-73b1-4eb7-9430-55b916f19ef7/12c0cbb7b7254e5c02bb7ff0f0c4aa3f

The error indicates that a problem exists within config/locales/users.en.yml, that a Hash was expected, but none was returned. 该错误表明config / locales / users.en.yml中存在问题,预期为哈希,但未返回任何哈希。

Currently config/locales/users.en.yml is a blank file. 当前config / locales / users.en.yml是空白文件。

Fix: 固定:

You can either delete that file. 您可以删除该文件。 Do this if you never plan on using it. 如果您从不打算使用它,请执行此操作。

OR 要么

add content so that parsing the file returns data in the form of a Hash. 添加内容,以便解析文件以哈希形式返回数据。 Simply add en: to the top of config/locales/users.en.yml. 只需在config / locales / users.en.yml的顶部添加en: :。 Do this if you plan on entering translation data in the future. 如果您打算将来输入翻译数据,请执行此操作。

Other: 其他:

It seems like you are developing your application on Heroku. 似乎您正在Heroku上开发应用程序。 From my experience this will be difficult. 根据我的经验,这将是困难的。 It is much easier to develop locally adding features and fixing bugs. 在本地开发添加功能和修复错误要容易得多。 Then deploy to Heroku once your app is in a stable state. 一旦您的应用程序处于稳定状态,然后将其部署到Heroku。 You can even set up a separate staging server on Heroku so you can test your changes before deploying to your production server. 您甚至可以在Heroku上设置单独的登台服务器,以便在部署到生产服务器之前测试更改。

Using the heroku gem you can run heroku logs --tail to monitor output from your application. 使用heroku gem,您可以运行heroku logs --tail来监视应用程序的输出。 If you had not been using that it may have helped solve your problem. 如果您没有使用过,它可能有助于解决您的问题。

Good luck! 祝好运!

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

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