0
UPDATE紅寶石顯示對象
我型我秀功能
def show
@contact = Contact.find(params[:id])
@data = Register.all :include => {:session =>[:term, :course]} , :conditions => ["contact_id = ?", params[:id]]
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @contact }
end
末
模型
class Register < ActiveRecord::Base
belongs_to :session
belongs_to :contact
end
class Session < ActiveRecord::Base
belongs_to :term
belongs_to :course
has_many :registers
has_many :contacts, :through => :registers
end
嗨,
我是一種新的以Ruby on Rails的。我想顯示如下 -
- !ruby/object:Register
attributes:
created_at: 2010-06-20 11:39:06
updated_at: 2010-06-20 11:39:06
session_id: "32"
contact_id: "601"
id: "1"
attributes_cache: {}
session: !ruby/object:Session
attributes:
created_at: 2010-06-19 10:16:13
term_id: "26"
updated_at: 2010-06-19 10:16:13
id: "32"
course_id: "4"
attributes_cache: {}
course: !ruby/object:Course
attributes:
created_at: 2010-05-30 14:36:24
updated_at: 2010-05-30 14:36:28
course_name: Beginner
id: "4"
course_type: Running
attributes_cache: {}
term: &id001 !ruby/object:Term
attributes:
number: "1"
start_date: "2010-06-19"
created_at: 2010-06-19 10:16:13
updated_at: 2010-06-19 10:16:13
id: "26"
attributes_cache: {}
我覺得我做錯了
<% @data.Register.each do |c| %>
<tr>
<td><%=h c.Term.number %></td>
<td><%=h c.Course.course_name %></td>
</tr>
<% end %>
感謝
感謝您的回覆,我添加了我的控制器方法和一些模型代碼。 是的關係工作,我想我正在做我的發現錯誤。 – Alex 2010-06-20 17:57:20
查看你的development.log,看看你的sql是否是你想要的。此外,應該可能是︰@contact = Contact.find(params [:id] .to_i) – 2010-06-20 20:56:22
謝謝,我會玩弄它。 – Alex 2010-06-21 21:49:21