title: How to display validation errors when using nested forms?
body: <p>First of all sorry about my English and about my knowledge of Rails, I am beginner who just started.</p>
  
  <p>I have 2 models with relations:</p>
  
  <p>CargoItems:</p>
  
  <pre><code>class CargoItem &lt; ActiveRecord::Base
    belongs_to :cargo
    attr_accessible :cargo_id, :height, :length, :pieces, :weight, :width
    validates :cargo, :height, :length, :width, :weight, :pieces, presence: true
    validates :height, :length, :width, :pieces, numericality: { only_integer: true, greater_than_or_equal_to: 1}
    validates :weight, numericality: { only_integer: true, greater_than_or_equal_to: 100}
  end
  </code></pre>
  
  <p>Cargos:</p>
  
  <pre><code>class Cargo &lt; ActiveRecord::Base
    belongs_to :airport
    belongs_to :user
    belongs_to :cargo_state
    belongs_to :cargo_price
    belongs_to :cargo_description
    has_many :cargo_items, :inverse_of =&gt; :cargo, :dependent =&gt; :destroy
  
    attr_accessible :departure_date, :cargo_state_id, :airport_id, :cargo_price_id, :cargo_description_id, :cargo_items_attributes
    accepts_nested_attributes_for :cargo_items, :allow_destroy =&gt; true, :reject_if =&gt; :all_blank
    validates_associated :cargo_items
    validates :departure_date, :cargo_state, :airport, :cargo_price, :cargo_description, presence: true
    validates :departure_date, date: { after: Proc.new { Date.today - 1.day }, before: Proc.new { Time.now + 1.year } }, :on =&gt; :create
    default_scope :order =&gt; 'departure_date DESC'
  end
  </code></pre>
  
  <p>I use following GEMs: simple_forms, nested_forms. This is form to add new Cargo with multiple CargoItems (they have possibility to be added dynamically) belonging to Cargos:</p>
  
  <pre><code>&lt;%= simple_nested_form_for @cargo, :wrapper =&gt; false do |f| %&gt;
  &lt;%= f.association :airport, :label_method =&gt; :full_airport_name, :value_method =&gt; :id , :order =&gt; :iata_code %&gt;
  &lt;%= f.input :departure_date , as: :date, start_year: Date.today.year,
  end_year: Date.today.year + 16,
  order: [:day, :month, :year] %&gt;
  &lt;%= f.association :cargo_description, :label_method =&gt; :description, :value_method =&gt; :id, :order =&gt; :description %&gt;
  &lt;%= f.association :cargo_price, :label_method =&gt; :price, :value_method =&gt; :id %&gt;
  &lt;%= f.association :cargo_state, :label_method =&gt; :state, :value_method =&gt; :id %&gt;
  &lt;hr&gt;
  &lt;table&gt;
      &lt;tr&gt;
          &lt;th&gt;&lt;%= :length %&gt;&lt;/th&gt;
          &lt;th&gt;&lt;%= :width %&gt;&lt;/th&gt;
          &lt;th&gt;&lt;%= :height %&gt;&lt;/th&gt;
          &lt;th&gt;&lt;%= :weight %&gt;&lt;/th&gt;
          &lt;th&gt;&lt;%= :pieces %&gt;&lt;/th&gt;
      &lt;/tr&gt;
      &lt;%= f.simple_fields_for :cargo_items, @cargo_item do |cargo_items_fields| %&gt;
      &lt;tr class="fields"&gt;
          &lt;td&gt;&lt;%= cargo_items_fields.text_field :length %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%= cargo_items_fields.text_field :width %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%= cargo_items_fields.text_field :height %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%= cargo_items_fields.text_field :weight %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%= cargo_items_fields.text_field :pieces %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%= cargo_items_fields.link_to_remove "Remove this item", :confirm =&gt; 'Are you sure you want to remove this item?' %&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;% end %&gt;
  &lt;/table&gt;
  &lt;%= f.link_to_add "Add a item", :cargo_items %&gt;
  
  &lt;div class="actions"&gt;
      &lt;%= f.button :submit %&gt;
  &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Cargo controller:</p>
  
  <pre><code>  def new
      @cargo = Cargo.new
      @cargo_item = CargoItem.new
  
      respond_to do |format|
        format.html # new.html.erb
        format.json { render json: @cargo }
      end
    end
  
    def create
      @cargo = Cargo.new(params[:cargo])
      @cargo.user_id = current_user[:id]
  
      respond_to do |format|
        if @cargo.save
          format.html { redirect_to @cargo, notice: 'Cargo was successfully created.' }
          format.json { render json: @cargo, status: :created, location: @cargo }
        else
          format.html { render action: "new" }
          format.json { render json: @cargo.errors, status: :unprocessable_entity }
        end
      end
    end
  </code></pre>
  
  <p>My problem is, validation errors are not shown for CargoItems, model is actually validating. I am not able to save Cargos with CargoItems which does not fulfill validating rules. But in case validations are not met, Cargo is not saved and it just stayed on the same page without any notification that CargoItems fields are invalid. Cargos fields validation errors are shown properly.</p>
  
  <p>Thanx a lot for helping me.</p>