Paperclip problem for accepts_nested_attributes_for and reject_if

后端 未结 1 1047
旧时难觅i
旧时难觅i 2021-01-22 08:42

I am developing a rails 3 application.

class Post < ActiveRecord::Base
  has_many :attachments
  has_many :photos
  accepts_nested_attributes_for :attachments         


        
相关标签:
1条回答
  • 2021-01-22 09:26

    Seems like since Rails 3.0.3, the association that you want to destroy (attachments, photos) need to be loaded. Take a look at this ticket. A quick fix, which isn't so elegant is to load your association in your update method:

    @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
    

    FYI this is still necessary for Rails 3.0.4.

    0 讨论(0)
提交回复
热议问题