Module: AuditsHelper
- Defined in:
- app/helpers/audits_helper.rb
Instance Method Summary collapse
-
#blank_is_none(value) ⇒ Object
Given a
value, returns the string NONE if the value isblank?, otherwise returns the givenvalue. -
#change_set_iter(change_set, &block) ⇒ Object
Allows you to iterate over a given Audit#change_set.
Instance Method Details
#blank_is_none(value) ⇒ Object
Given a value, returns the string NONE if the value is blank?, otherwise returns the given value
4 5 6 |
# File 'app/helpers/audits_helper.rb', line 4 def blank_is_none(value) value.blank? ? "NONE" : value end |
#change_set_iter(change_set, &block) ⇒ Object
Allows you to iterate over a given Audit#change_set. Given a block, each time yield is called, it will return the attribute, the old version and the new version as arguments. If the Audit is a message audit, it will set the new attribute to the audit message.
Example:
<% change_set_iter(audit.change_set) do |attr, old, new| %>
<p class="audit"><strong><%=h attr %></strong>
<% if audit.message %>
<em><%= new %></em>
<% else %>
changed from <em><%=h old %></em> to <em><%=h new %></em>.
<% end %>
</p>
<% end %>
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/helpers/audits_helper.rb', line 23 def change_set_iter(change_set, &block) change_set.each_pair do |attr, change| if change.is_a?(Array) old_val = blank_is_none(change.first) new_val = blank_is_none(change.last) else old_val = blank_is_none("") new_val = blank_is_none(change) end yield attr.titleize, old_val, new_val end end |