undefined method `upload' for nil:NilClass Did you mean? load

I solved it by making sure that my Active Storage configuration in my environment file was set.

So, in development.rb, make sure the line

config.active_storage.service = :local

is present.


Try this:

@comment = Comment.new(params.require(:comment).permit(:content, :image))
@comment.save!
redirect_to comments_path 

ActiveRecord is smart enough to know that image is a file that is handled by ActiveStorage, so you don't need to manually attach it. I'm guessing that because the record is already persisted and the image isn't there it's throwing a fit.

Also you should move your strong params to a method.

def comment_params
  params.require(:comment).permit(:content, :image)
end 

And use like,

@comment = Comment.new(comment_params)
@comment.save!
redirect_to comments_path