Ruby on rails 错误消息不';t显示回形针验证错误消息
我有两个模型嵌套在的Ruby on rails 错误消息不';t显示回形针验证错误消息,ruby-on-rails,ruby-on-rails-3,paperclip,nested-attributes,Ruby On Rails,Ruby On Rails 3,Paperclip,Nested Attributes,我有两个模型嵌套在的接受\u嵌套的\u属性\u中: class Place < ActiveRecord::Base # Relations.. accepts_nested_attributes_for :place_photos, :allow_destroy => true # others methods... end classplacetrue #其他方法。。。 结束 -- class PlacePhoto{:small=>“120>”,:large=>“
接受\u嵌套的\u属性\u中:
class Place < ActiveRecord::Base
# Relations..
accepts_nested_attributes_for :place_photos, :allow_destroy => true
# others methods...
end
classplacetrue
#其他方法。。。
结束
--
class PlacePhoto{:small=>“120>”,:large=>“640x480>”}
验证\u附件\u是否存在:映像
验证附件大小:图像,:小于=>500.KB,
:if=>Proc.new{| imports |!imports.image_file_name.blank?},
:message=>“此消息可能不会显示!:P”
结束
以下是用于添加图像的视图:
<%= form_for([:profile, @place], :html => {:multipart => true }) do |f| %>
<% if @place.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@place.errors.count, "error") %> prohibited this place from being saved:</h2>
<ul>
<% @place.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
# ...
<%= f.fields_for :place_photos do |p| %>
<% if p.object.new_record? %>
<div> <%= image_tag("place_avatar.png", :class => "listTabsImg", :height => '120', :width => '120') %>
<div class="listTabsTxt">
<span>Upload new image</span> <br/>
<%= p.file_field :image %><br/>
<div class="clear"></div>
</div>
</div>
<br/>
<% end %>
<% end %>
<%= f.submit "Upload all", :class => "btnGB" %>
<% end %>
{:multipart=>true})do | f |%>
禁止保存此位置:
# ...
“listTabsImg”,:高度=>'120',:宽度=>'120')%>
上载新图像
“btnGB”%>
不幸的是,没有显示回形针验证错误消息(即:“此消息可能不会显示!:p”)
这是否可以解决该问题?问题在控制器中。我使用:
重定向到照片路径
而不是:
render:action=>“编辑”
重定向_以覆盖@object
(直接调用编辑操作),从而清除@object.errors
当我看到这一点时,我只是笑了:D
<%= form_for([:profile, @place], :html => {:multipart => true }) do |f| %>
<% if @place.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@place.errors.count, "error") %> prohibited this place from being saved:</h2>
<ul>
<% @place.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
# ...
<%= f.fields_for :place_photos do |p| %>
<% if p.object.new_record? %>
<div> <%= image_tag("place_avatar.png", :class => "listTabsImg", :height => '120', :width => '120') %>
<div class="listTabsTxt">
<span>Upload new image</span> <br/>
<%= p.file_field :image %><br/>
<div class="clear"></div>
</div>
</div>
<br/>
<% end %>
<% end %>
<%= f.submit "Upload all", :class => "btnGB" %>
<% end %>