第28回/ユーザフィールドに簡単に「自分」を設定できるとうれしい
概要:
確認:
author_valuesは app/models/query.rb で定義されている
code:ruby
def author_values
author_values = []
author_values +=
users.sort_by(&:status).
collect{|s| [s.name, s.id.to_s, l("status_#{User::LABEL_BY_STATUSs.status}")]} author_values
end
フォームの担当者は views/issues/_attributes.html.erb 内で表示
code:ruby
<% if @issue.safe_attribute? 'assigned_to_id' %>
<p>
<%= f.select :assigned_to_id, principals_options_for_select(@issue.assignable_users, @issue.assigned_to),
:include_blank => true, :required => @issue.required_attribute?('assigned_to_id') %>
<% if @issue.assignable_users.include?(User.current) %>
<a class="assign-to-me-link<%= ' hidden' if @issue.assigned_to_id == User.current.id %>" href="#" data-id="<%= User.current.id %>"><%= l(:label_assign_to_me) %></a>
<% end %>
</p>
<% end %>
フォームのカスタムフィールドは views/issues/_form_custom_fields.html.erb 内で表示
code:ruby
:
既存の Assing Current Userプラグインが参考になるかもしれない。ただ、1つのカスタムフィールドにしか対応できない。
Hookの処理自体はすごく簡単なので、こちらの流用を検討してみる