1
我已經簽出了關於此的文檔,但我仍然有點困惑。我的目標是返回@mom上的內容字段。但是它會因未定義的方法「內容」而失敗。和@goals的作品。我錯過了關於@mom的內容,我該怎麼做才能工作?Rails3困惑於活躍的關係
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
嘆息......這是漫長的一天。謝謝! – jlarry 2011-06-10 00:54:25