<% if @issue.new_record? && User.current.allowed_to?(:add_issue_watchers, @project) -%>
<p><label><%= l(:label_issue_watchers) %></label>
<% @issue.project.users.sort.each do |user| -%>
-<label class="floating"><%= check_box_tag 'issue[watcher_user_ids][]', user.id, @issue.watcher_user_ids.include?(user.id) %> <%=h user %></label>
+<label class="floating"><%= check_box_tag 'issue[watcher_user_ids][]', user.id, @issue.watched_by?(user) %> <%=h user %></label>
<% end -%>
</p>
<% end %>
watching ? add_watcher(user) : remove_watcher(user)
end
- # Returns if object is watched by user
+ # Returns true if object is watched by user
def watched_by?(user)
- !self.watchers.find(:first,
- :conditions => ["#{Watcher.table_name}.user_id = ?", user.id]).nil?
+ !!(user && self.watchers.detect {|w| w.user_id == user.id })
end
# Returns an array of watchers' email addresses