Update the Post
model as below:
class Post < ActiveRecord::Base
has_many :images
accepts_nested_attributes_for :images ## Add this
end
This way upon form submission you would receive the image attributes in key images_attributes
and not image
which you are currently receiving which is causing the warning as Unpermitted parameters: image
As you have 1-M relationship
between Post
and Image
You need to update post_params
as below:
def post_params
params.require(:post).permit(:title, :content, images_attributes: [:id, :post_id, :file])
end
Use images_attributes
(Notice plural images) and NOT image_attributes
(Notice singular image)
And change fields_for
in your view as
<%= post.fields_for :images, :html => { :multipart => true } do |image| %>
Use images
(Notice plural) and NOT image
(Notice singular)
UPDATE
To resolve uninitialized constant Post::Image
error
Update Image
model as below:
class Image < ActiveRecord::Base
belongs_to :post
## Updated mount_uploader
mount_uploader :file, ImagesUploader, :mount_on => :file
end
Also, suggested to remove multiple: :true
from
<%= ff.file_field :file, multiple: true %>