Ruby on rails 论积极关系
我已经检查了这方面的文件,但我还是有点困惑。我的目标是返回@mom上的内容字段。但它在使用未定义的方法“content”时失败。而且@goals是有效的。关于@mom,我遗漏了什么?我如何才能让它发挥作用 project_controller.rbRuby 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")
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