这些是传递给我的HTTP POST请求的参数,如下所示:
Parameters: {
"vision"=>{
"description"=>"dsfsfdsfdsfsd",
"image"=>"file:///Users/ozgecokyasar/Library/Developer/
CoreSimulator/Devices/EDD6C498-DACD-433E-B96D-3A30BAE7BA6D/data/
Containers/Data/Application/
6F633096-E665-46BB-952F-2775DD85A4A6/Library/Caches/
ExponentExperienceData/%2540anonymous%252Fmanifestation-react-
3ac1cbe2-549f-
49e7-8506-ef29638d1643/ImagePicker/0E426602-8110-4A9C-8B9A-
96D0BF1B2ECE.jpg"
}
}
但是,它照原样保存(图像为零):
SQL (2.1ms) INSERT INTO "visions" ("image", "description", "created_at",
"updated_at", "user_id") VALUES ($1, $2, $3, $4, $5) RETURNING "id"
[["image", nil], ["description", "dsfsfdsfdsfsd"], ["created_at", "2019-
01-12 01:14:34.341356"],["updated_at", "2019-01-12 01:14:34.341356"],
["user_id", 3]]
为什么图片列为零?
visions_controller.rb:
def create
@vision = current_user&.visions.build(vision_params)
@vision.remote_image_url = params[:image]
@vision.save
render :create, status: :created
end
视觉模型:
class Vision < ApplicationRecord
belongs_to :user
mount_uploader :image, ImageUploader
end
但是,如果将visions_controller中的create动作更改为:
,我就能成功地将远程URL保存到我的图像列中。 def create
@vision = current_user&.visions.build(vision_params)
@vision.remote_image_url = 'ANY REMOTE IMAGE URL'
@vision.save
render :create, status: :created
end
为什么当我添加params [:image]时,传递的图像参数被保存为nil?