2

私は2つのモデルがaccepts_nested_attributes_forを入れ子にしている: - :エラーメッセージが

<%= 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 %> 

class Place < ActiveRecord::Base 
    # Relations.. 
    accepts_nested_attributes_for :place_photos, :allow_destroy => true 
    # others methods... 
end 

ここ

class PlacePhoto < ActiveRecord::Base 

    belongs_to :place 
    # attr_accessible :photo_index                                
    has_attached_file :image, :styles => { :small => "120>", :large => "640x480>"} 
    validates_attachment_presence :image 
    validates_attachment_size :image, :less_than => 500.kilobytes, 
     :if => Proc.new {|imports| !imports.image_file_name.blank? }, 
     :message => "This message probably won't be shown! :P" 
end 

は、追加の画像の図です。

Unfortunatelly Paperclipの検証エラーメッセージは表示されません(「このメッセージは表示されません!:P ")。

この問題を解決することは可能ですか?

答えて

3

問題がコントローラにありました。私が使用します。

redirect_to photos_path

の代わりに:

render :action => "edit"

@object(直接編集アクションを呼び出す)、そう@object.errorsが洗浄されて上書きされredirect_to。

私はそれを見たとき、私はただlol'ed。 :D

関連する問題