2011-01-22 2 views
2

레일 3 애플리케이션을 개발 중입니다.accepts_nested_attributes_for 및 reject_if에 대한 클립 클립 문제

class Post < ActiveRecord::Base 
    has_many :attachments 
    has_many :photos 
    accepts_nested_attributes_for :attachments, :allow_destroy => true, :reject_if => proc { |attrs| attrs['document'].blank? } 
    accepts_nested_attributes_for :photos, :allow_destroy => true, :reject_if => proc { |attrs| attrs['image'].blank? } 
end 

class Attachment < ActiveRecord::Base 
    belongs_to :post  
    has_attached_file :document 
end 

class Photo < ActiveRecord::Base 
    belongs_to :post  
    has_attached_file :image, :styles => { 
             :thumb => "100x100#", 
             :small => "150x150>", 
             :mid => "640x640>", 
             :large => "800x800>" 
             } 

end 

문제는 "_destroy"=> "1"이 첨부 파일과 사진에 대해 작동하지 않는다는 것입니다. reject_if 옵션을 제거하면 작동한다는 것을 알았습니다. 무엇이 잘못 되었나요?

감사합니다. 레일 3.0.3, 당신은 (첨부 파일, 사진)를 파괴하려는 연결하기 때문에로드 할 필요 같은 샘

답변

1

보인다. this ticket을 살펴보십시오. 그다지 우아하지 않은 빠른 수정 방법은 업데이트 방법에서 협회를로드하는 것입니다.

@post = Post.includes(:attachments).find(params[:id]) 

if @post.update_attributes(params[:post]) 
    redirect_to(posts_url, :notice => 'Post updated.' 
else 
    render :action => "edit" 
end 

참고 Rails 3.0.4에서는 여전히 필요합니다.

+1

예. 티켓은 나에 의해 발급되었다 :-) 어쨌든 고마워. –

+0

죄송합니다. 그럼 곧 진짜 수정에 대한 희망을 갖게됩니다. – mud

+0

연결로드로 인해 문제가 해결되지 않았습니다. – Eytan