Paperclip in Rails 4 - Strong Parameters Forbidden Attributes Error

前端 未结 2 799
北海茫月
北海茫月 2020-12-16 19:21

Having a problem with a Paperclip upload in Rails 4 - failing on ForbiddenAttributesError (strong parameters validation). Have the latest paperclip gem and latest rails 4 g

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-16 19:28

    It looks like your first one should have worked. This is what I use for my projects.

    class GalleriesController < ApplicationController
    
      def new
        @gallery = Gallery.new
      end
    
      def create
        @user.galleries.new(gallery_params)
      end
    
      private
    
      #note cover_image is the name of paperclips attachment filetype(s)
      def gallery_params
        params.require(:gallery).permit(:cover_image)
      end
    end
    

提交回复
热议问题