Created
December 1, 2008 13:51
-
-
Save lazyatom/30729 to your computer and use it in GitHub Desktop.
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
<form ...> | |
<input type="checkbox" name="user[email_enabled]"> | |
<input type="radio" name="user[email_settings]" value="pm_daily"> | |
<input type="radio" name="user[email_settings]" value="pm_instant"> | |
... | |
</form> | |
class Controller | |
def update | |
@user = User.find(params[:id]) | |
@user.update_attributes(params[:user].except(:email_enabled, :email_settings)) | |
update_email_settings(@user, params[:user]) | |
@user.save! | |
end | |
private | |
def update_email_settings(user, params) | |
if params[:email_enabled] | |
if params[:email_settings] == "pm_daily" | |
user.enable_daily_emails | |
elsif params[:email_settings] == "pm_instant" | |
user.enable_instance_emails | |
end | |
else | |
user.disable_emails | |
end | |
end | |
end | |
class User | |
def enable_daily_emails | |
self.pm_daily = true | |
self.pm_instance = false | |
end | |
def enable_instant_emails | |
self.pm_daily = false | |
self.pm_instant = true | |
end | |
def disable_emails | |
self.pm_daily = false | |
self.pm_instant = false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment