B
B
bismoney2015-10-30 06:35:42
Ruby on Rails
bismoney, 2015-10-30 06:35:42

Why isn't Paperclip working?

Hi friends! Please help me with this animal.
Migration

create_table :post_attachments do |t|
      t.attachment :photo
      
      t.timestamps

PostAttachments Model
class PostAttachment < ActiveRecord::Base
  belongs_to :post
  has_attached_file :photo, :styles => { :mini => "260x180#", :normal => "800x400#" }
end

Post Model
has_many :post_attachments
accepts_nested_attributes_for :post_attachments

Post controller
params.require(:post).permit(:title, :body, post_attachments_attributes: [:id, :photo]

If everything is so, then I get it in the logs
Unpermitted parameter: post_attachments
. If I add an associative object to the Post controller
def new
    @post = Post.new
    @post.build_post_attachments
  end

I get an error
undefined method `build_post_attachments' for
Thanks.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
N. Bekseitov, 2015-10-30
@bismoney

May need to add post_id to post_attachments table

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question