title: How to show validation errors from an associated model in Rails?
body: <p>I have 3 models: User, Swatch + Color. A user has many swatches, and a swatch references a color.</p>
  
  <p>Users create swatches on their profile page (users/show/id).</p>
  
  <p>The color model handles validation through the swatch model with <code>accepts_nested_attributes_for :color</code> and <code>validates_associated :color</code>.</p>
  
  <p>My question is, how to show the color-specific validation errors on the User profile page?</p>
  
  <p>This is the swatches controller. I currently just show a generic error message with the flash, but would like to access the real ActiveRecord::Errors from the color model:</p>
  
  <pre><code>class SwatchesController &lt; ApplicationController
  
    before_filter :authenticate
  
    def create 
      color = Color.find_or_create_by_value(params[:swatch][:colors][:value])    
      @swatch = current_user.swatches.build(:color_id =&gt; color.id)
  
      if @swatch.save
        flash[:success] = "Swatch created"
        redirect_to user_path(current_user)
      else
        flash[:error] = "Error"
        redirect_to user_path(current_user)              
      end
    end
  
  end
  </code></pre>