Paperclip in Rails 4 - Strong Parameters Forbidden Attributes Error

旧街凉风 提交于 2019-11-29 04:04:19

I understand what happened here now - and will leave this up in the hope it helps someone else. I was porting code from a rails 3 project and missed the line that created the image:

@image = current_user.images.new(params[:image])

In rails 4 this is incorrect (I beleive). I updated to

@image = current_user.images.new(image_params)

and that solved my problem.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!