Skip to content

Instantly share code, notes, and snippets.

@patrick99e99
Created August 15, 2011 17:38
Show Gist options
  • Save patrick99e99/1147275 to your computer and use it in GitHub Desktop.
Save patrick99e99/1147275 to your computer and use it in GitHub Desktop.
<p>
<%= f.label :roles %><br />
<% for ns in User::NOTIFICATION_SETTINGS %>
<%= check_box_tag "user[notification_settings][]", ns, @user.notification_settings.include?(ns) %>
<%=h notification_setting.humanize %><br />
<% end %>
</p>
class PostObserver << ActiveRecord::Observers
after_create(post)
if post.user.notification_settings.include?(:post_created)
send_the_mother_fucker
end
end
end
class User
NOTIFICATION_SETTINGS = [:post_created,
:post_closed,
:reply_created,
:reply_helpful,
:offer_created,
:offer_accepted,
:offer_rejected,
:offer_cancelled
:feedback_available,
:feedback_left,
:order_created,
:alert]
def notification_settings=(settings)
self.ns_mask = (settings & NOTIFICATION_SETTINGS).sum { |ns| 1 << NOTIFICATION_SETTINGS.index(ns) }
end
def notification_settings
NOTIFICATION_SETTINGS.reject { |ns| (ns_mask || 0)[NOTIFICATION_SETTINGS.index(ns)].zero? }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment