Created
January 23, 2011 15:42
-
-
Save caike/792152 to your computer and use it in GitHub Desktop.
serializing preferences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in the user form partial | |
<h3>Preferences</h3> | |
<% User::PREFERENCES.each do |preference| %> | |
<div class="field"> | |
<%= check_box_tag "user[preferences[#{preference.to_s}]]", "1", @user.preferences ? @user.preferences[preference] : false %> | |
<%= label_tag :attribute, preference.to_s.titleize %> | |
</div> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
has_many :tweets | |
has_one :account_setting, :dependent => :destroy | |
accepts_nested_attributes_for :account_setting | |
validates_presence_of :first_name, :last_name, :email | |
validates_uniqueness_of :email | |
PREFERENCES = [:notify_retweet, :notify_direct_messages, :notify_new_follower] | |
serialize :preferences, Hash | |
def to_s | |
"#{first_name} #{last_name}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment