I am trying to find all associated tickets with an employee. I am very
new to HABTM so I am having some trouble.
view: time.html.erb
[code]
<h1>Time Report for <%= @employee.name %></h1>
<table cellpading="10" cellspacing="10"
style="width:700px">
<thead>
<tr>
<th>Job #</th>
<th>Company</th>
<th>Project</th>
<th></td>
</tr>
</thead>
<tbody>
<% for ticket in @employee %>
<tr class="<%= cycle(''odd'',
''even'') %>">
<td>
<%= @employee.ticket.id %>
</td>
</tr>
<% end %>
</table>
[/code]
Controller:
[code]
def time
@employee = Employee.find(params[:id], :include => { :tickets =>
:workorder} )
end
[/code]
Employee Model:
[code]
class Employee < ActiveRecord::Base
has_and_belongs_to_many :tickets
validates_uniqueness_of :name
end
[/code]
Ticket Model
[code]
class Ticket < ActiveRecord::Base
has_and_belongs_to_many :employees
belongs_to :workorder
end
[/code]
Error
[code]
NoMethodError in Employees#time
Showing employees/time.html.erb where line #13 raised:
undefined method `each'' for #<Employee:0x326b044>
[/code]
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---