Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.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_Active Relation - Fatal编程技术网

Ruby on rails 论积极关系

Ruby on rails 论积极关系,ruby-on-rails,active-relation,Ruby On Rails,Active Relation,我已经检查了这方面的文件,但我还是有点困惑。我的目标是返回@mom上的内容字段。但它在使用未定义的方法“content”时失败。而且@goals是有效的。关于@mom,我遗漏了什么?我如何才能让它发挥作用 project_controller.rb def show @project = Project.find(params[:id]) @goals = @project.projectgoals.find(:first, :order => "created_at DESC")

我已经检查了这方面的文件,但我还是有点困惑。我的目标是返回@mom上的内容字段。但它在使用未定义的方法“content”时失败。而且@goals是有效的。关于@mom,我遗漏了什么?我如何才能让它发挥作用

project_controller.rb

def show
  @project = Project.find(params[:id])
  @goals = @project.projectgoals.find(:first, :order => "created_at DESC")
  @mom = @project.projectgoals.order(:created_at => "DESC").limit(1).all
end
Show.html.erb

<b>Name: </b><%= @project.name %><br/>
<b>Goals: </b><%= @goals.content %><br/>
<b>Goals: </b><%= @mom.content %>
<br/>
<%= debug @mom %>
名称:
目标:
目标:
模型

class Projectgoal < ActiveRecord::Base
  attr_accessible :content, :project_id
  belongs_to :projects
end

class Project < ActiveRecord::Base
  attr_accessible :name
  has_many :projectgoals
  has_many :projectstatuses
end
class Projectgoal
在控制器中尝试此操作(它将返回一条记录,而不是一个包含一条记录的数组):


叹气这是漫长的一天。谢谢
@mom = @project.projectgoals.order("created_at DESC").first