Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 轨道不';t在关联模型上显示验证错误消息_Ruby On Rails_Validation - Fatal编程技术网

Ruby on rails 轨道不';t在关联模型上显示验证错误消息

Ruby on rails 轨道不';t在关联模型上显示验证错误消息,ruby-on-rails,validation,Ruby On Rails,Validation,我有一个简单但令人沮丧的问题,就是为帖子的评论显示验证错误。Error partial显示帖子的错误,但尽管对注释进行了验证,但不会显示错误 注释表单部分插入到post视图中: <%= form_for([@post, @post.comments.build]) do |f| %> <%= render 'shared/error_messages', object: f.object %> <p> <%= f.label :comme

我有一个简单但令人沮丧的问题,就是为帖子的评论显示验证错误。Error partial显示帖子的错误,但尽管对注释进行了验证,但不会显示错误

注释表单部分插入到post视图中:

<%= form_for([@post, @post.comments.build]) do |f| %>
  <%= render 'shared/error_messages', object: f.object %>
  <p>
    <%= f.label :commenter %><br>
    <%= f.text_field :commenter %>
  </p>
  <p>
    <%= f.label :body %><br>
    <%= f.text_area :body %>
  </p>
  <p>
    <%= f.submit %>
  </p>
<% end %>




偏误

<% if object.errors.any? %>
<h2>Errors:</h2>
<ul>
  <% object.errors.full_messages.each do |msg| %>
    <li><%= msg %></li>
  <% end %>  
</ul>

错误:
型号:

 class Post < ActiveRecord::Base
  has_many :comments, dependent: :destroy

  validates :title, :content, :presence => true
  validates :title, length: { minimum: 3 }
  validates :title, :uniqueness => true

end

class Comment < ActiveRecord::Base
  belongs_to :post

  validates :body,      presence: true
  validates :commenter, presence: true, length: { minimum: 3 }

end
class Posttrue
验证:标题,长度:{最小值:3}
验证:title,:university=>true
结束
类注释

我寻找答案已经有一段时间了,但无法让它工作。

将这一行添加到
Post
模型中

验证\u相关:注释

您有没有找到解决方案?