Created
          December 22, 2011 22:40 
        
      - 
      
- 
        Save dnch/1512171 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 FoosController < AbstractController::Base | |
| def update | |
| @foo = Foo.find(params[:id]) | |
| # If our changed object saves... | |
| if @foo.update_attributes(params[:attributes]) | |
| # Now, we check for changes. In some situations, we might | |
| # use @foo.notify_changed? but given that update_attributes | |
| # clobbers the dirty state of your instance, we need to | |
| # use previous_changes | |
| if @foo.previous_changes[:notify] | |
| # flash? | |
| redirect_to @foo, notice: "Flash message in flash[:notice]" | |
| else | |
| # do something else? | |
| end | |
| # Otherwise, handle our error | |
| else | |
| render action: "edit" | |
| end | |
| end | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment