0

単純なモデルのようにエラーを表示するこのようなフォームを作成することはできますか? http://i.imgur.com/8t6ef.png

2つのモデルを作成します...しかし、フォームに間違って入力すると..エラーメッセージは表示されず、エラーRails画面に、たとえば「検証に失敗しました:フィールド1を空白にすることはできません...」と表示されます

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

モデル:

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

例や提案はありますか?

4

1 に答える 1

1

あなたの見解には次の行がありますか?

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

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

<% end %>
于 2012-05-21T09:02:52.830 に答える