Topic: a Multi-Model Form with display validate errors?

Is posible create this kind forms with displaying errors like a simple model? http://i.imgur.com/8t6ef.png

I get create two models... but if I fill incorrectly the form.. the errors messages won't appears and error Rails screen say me, for example, "validation failed: field1 can't be blank..."

http://i.imgur.com/6KvVh.png

Last edited by ramirami (2012-05-16 13:53:15)

Re: a Multi-Model Form with display validate errors?

Can you post your model code?

Re: a Multi-Model Form with display validate errors?

Hi themusicman,

here my models code:

class Step < ActiveRecord::Base

  #validates
  validates :tree_id, :presence => true, :numericality => true
  validates :is_first, :presence => true, :length => {:maximum => 1}
  validates :status, :presence => true, :numericality => true
  validates :step_type_id, :presence => true

  #relations
  belongs_to :step_type
  belongs_to :tree
  has_many :statements

  accepts_nested_attributes_for :statements

end

class Statement < ActiveRecord::Base

  #validates
  validates :step_id, :presence => true, :numericality => true
  validates :title, :presence => true, :length => {:maximum => 255}
  validates :statement, :presence => true
  validates :help, :presence => true
  validates :is_last_version, :presence => true, :length => {:maximum => 1}


  #relations
  belongs_to :step
  has_many :transitions

end

Re: a Multi-Model Form with display validate errors?

Sorry should have looked at the image more closely. You are using save! or create! in the controller which raises an exception when validation fails instead of save or create that just return true or false. I would checkout the following Railscasts: http://railscasts.com/episodes/211-vali … in-rails-3