Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在视图中显示关联的数据_Ruby On Rails - Fatal编程技术网

Ruby on rails 在视图中显示关联的数据

Ruby on rails 在视图中显示关联的数据,ruby-on-rails,Ruby On Rails,我有两个模型,考试和考试。他们之间的关系是,考试有一个考试费,而考生属于考试。以下是模型: class ExamFee < ActiveRecord::Base belongs_to :examination end class Examination < ActiveRecord::Base has_one :exam_fee has_many :exam_statuses end classexamfee

我有两个模型,考试和考试。他们之间的关系是,考试有一个考试费,而考生属于考试。以下是模型:

class ExamFee < ActiveRecord::Base
    belongs_to :examination
end

class Examination < ActiveRecord::Base
    has_one :exam_fee
    has_many :exam_statuses
end
classexamfee
协会运作良好,没有任何问题。我可以将ExamFees分配给考试,当我从Rails控制台进行检查时,它们运行良好。但是,

“app/views/executions/index.html.erb”中,我想显示(从每个考试的ExamFee模型中获取相关考试费用数据)每个考试的考试费用。我该怎么做

app/views/executions/index.html.erb文件:

<% @examinations.each do |examination| %>
<tr>
<td><%= examination.full_name %></td>
<td><%= examination.exam_date %></td>
<td><%= I WANT TO SHOW EXAMFEE FROM EXAM_FEE MODEL HERE %></td>
<td>Başvuru</td>
</tr>
<% end %>

巴武鲁

提前谢谢。

不确定数据库中的字段名,但您可以试试

examination.exam_fee.field_name

把你的模型代码也放进去,这样就很容易给出一个准确的解决方案,所以我建议你立即加载考试费用模型,否则你会反复点击数据库,不要忘记接受答案