UPDATE
my show function
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
end
Models
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
Hi,
I am kind of new to ruby on rails. I want to display the following -
- !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: {}
I think I'm doing it wrong
<% @data.Register.each do |c| %>
<tr>
<td><%=h c.Term.number %></td>
<td><%=h c.Course.course_name %></td>
</tr>
<% end %>
Thanks