如何修复错误"没有将nil隐式转换为String" ???
我的迁移(对于postgresql):
class CreateFotos < ActiveRecord::Migration
def change
create_table :fotos do |t|
t.json :path, null: false, default: '{}'
t.string :title
t.boolean :show
end
end
end
我的模特:
class Foto < ActiveRecord::Base
mount_uploader :path, FotoUploader
end
我的控制器:
class FotoUploaderController < ApplicationController
def create
@foto = Foto.new(foto_params)
if @foto.save!
redirect_to root_path
else
flash[:notice] = "Didn't work"
redirect_to foto_uploader_upload_path
end
end
private
def foto_params
params.require(:foto).permit(:title, {path:[]}, :show)
end
end
我的参数:
{"utf8"=>"✓", "authenticity_token"=>"38YKuM3gibtrvr+Sd3C89chTh+kfEuVihbHyeUBxKDALxgSzZYhKL6zshevKjEtazXoiArm1YSryi4U+P4Vb3w==",
"foto"=>{"path"=>[#<ActionDispatch::Http::UploadedFile:0x007f5e4e996318 @tempfile=#<Tempfile:/tmp/RackMultipart20160111-7835-ztbjyj.jpg>,
@original_filename="3.jpg",
@content_type="image/jpeg",
@headers="Content-Disposition: form-data; name=\"foto[path][]\"; filename=\"3.jpg\"\r\nContent-Type: image/jpeg\r\n">],
"title"=>"1",
"show"=>"1"},
"commit"=>"upload"}