class Job < ActiveRecord::Base
has_many :employments, :dependent => :destroy
has_many :users, :through => :employments
class User < ActiveRecord::Base
has_many :employments
has_many :jobs, :through => :employments
class Employment < ActiveRecord::Base
belongs_to :job
belongs_to :user # Employment has an extra attribute of confirmed ( values are 1 or 0)
在我的工作视图中,我想显示每项工作的确认值。我似乎无法得到它。 在我看来,我有:
<% @job.each do |job| %>
<tr class="<%= cycle('oddrow', 'evenrow') %>">
<td><%= link_to job.clientname, job_url(job.id) %></td>
<td><%= job.eventtype.name %></td>
<td><% unless job.starts_at.blank? %><%= job.starts_at.to_formatted_s(:full) %><% end %></td>
<td>7 - 12 </td>
<td><%= job.employment.confirmed %></td>
</tr>
<% end %>
由于
答案 0 :(得分:1)
查看您的工作模型。你已宣布它有很多就业机会。调用复数形式的协会(就业)将为您提供该职位的就业清单。
如果您只想要已确认的作业,则可以将以下命名范围添加到“就业”中:
named_scope :confirmed, :conditions => ['confirmed = ?', true]
然后拨打job.employments.confirmed
只会给您确认的工作。