Created
May 15, 2012 18:34
-
-
Save mixonic/2704020 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 SettingsController < ApplicationController | |
def update | |
if current_user.settings.update_attributes(params[:settings]) | |
render layout: nil, json: { } // Your object should go back as json | |
else | |
render status: 422, layout: nil, json: { errors: ['There was an unknown error updating your settings. Please contact support if the issue persists.'] } // Errors go back as 422 | |
end | |
end | |
end |
This file contains hidden or 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
// The error handling for rest objects is from a ember-data pull request: | |
// | |
// https://github.com/emberjs/data/pull/228 | |
// | |
// Merged in my branch as well: | |
// | |
// https://github.com/mixonic/data/tree/spinto | |
// | |
App.EditSettingsView = Ember.View.extend({ | |
templateName: 'ember/templates/editing_settings', | |
buttonDisabledBinding: "content.isSaving", | |
displayingErrors: false, | |
submit: function(event) { | |
event.preventDefault(); | |
App.store.commit(); | |
}, | |
setDisplayingErrors: function(){ | |
if (!this.getPath('content.isValid')) { | |
this.set('displayingErrors', true); | |
} else if (!this.getPath('content.isDirty')) { | |
this.set('displayingErrors', false); | |
} | |
}.observes('content.isValid','content.isDirty'), | |
setSuccessMessage: function(){ | |
if (this.getPath('content.isSaving')) { | |
this.set('saving', true); | |
} else if (this.get('saving')) { | |
this.set('saving', false); | |
this.$('.message').delay(1).html('Your settings have been saved, and the changes are live.').fadeIn(200).delay(2000).fadeOut(200); | |
} | |
}.observes('content.isSaving') | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment