简体   繁体   中英

Rails3: Display validate errors in a multi-model Form?

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

Models:

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

any example or suggestions?

Do you have the following lines in your view?

<% if @statement.errors.any? %>
  <% flash[:notice] = "Please correct!" %>

    <% for message in @statement.errors.full_messages %>
        <li class="cf-messages-li"><%= message %></li>
    <% end %>

<% end %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM