1

显示第 3 行引发的 app/views/flights/show.html.erb:

You have a nil object when you didn't expect it!
The error occurred while evaluating nil.name

Extracted source (around line #3):

1: <p>
2:  <b>Airline Name:</b>

3:  <%= @flight.airline.name %>

好吧,当我尝试提交“座位”表格时,就会发生上述错误。

我的航班/节目中有一个“_new_seat”“部分”页面。当点击“预订新座位”(提交)时,它应该重定向到座位/显示,但它没有..

是否需要在飞行控制器中使用额外的方法?...请帮助我。

4

1 回答 1

2

@flight没有airline关联。

要在没有airline关联时摆脱错误,请编写:

@flight.airline.try(:name)

要有airline关联。检查您的@flight对象属性。

首先,检查你有这个:

class Flight < ActiveRecord::Base
  belongs_to :airline

其次,您已airline_id在飞行实例中正确设置。

第三,您有一家航空公司,该航空公司airline_id保存在航空公司表中。

于 2013-05-20T06:14:25.653 回答