Ruby on rails 回形针图像未保存
我用回形针宝石上传图像,但图像没有保存 这是我的照片模型:Ruby on rails 回形针图像未保存,ruby-on-rails,paperclip,Ruby On Rails,Paperclip,我用回形针宝石上传图像,但图像没有保存 这是我的照片模型: class Photo < ApplicationRecord belongs_to :room has_attached_file :image, styles: {medium: '300x300>', thumb: '100x100>'}, :path => ':rails_root/public/images/:id/:style/:filename',
class Photo < ApplicationRecord
belongs_to :room
has_attached_file :image, styles: {medium: '300x300>', thumb: '100x100>'},
:path => ':rails_root/public/images/:id/:style/:filename',
:url => '/images/:id/:style/:filename'
validates_attachment_content_type :image, content_type: /\Aimage\/.*\z/
# do_not_validate_attachment_file_type :image
end
仅保存房间,但不保存照片模型。我尝试使用关系保存图像,但即使没有关系也无法工作图像无法保存。有人能帮我吗?很难说问题到底出在哪里。看起来你在用回形针
已附加\u文件方法。可能您上传的图像不符合验证要求,其类型与“image/jpg”、“image/jpeg”、“image/png”、“image/gif”等类型不同。你能提供你想要保存的图像吗。很难建议这样的解决方案。 将创建更改为创建以引发异常,然后可以更好地进行调试
def create
@room = current_user.rooms.build(room_params)
if @room.save
if params[:images]
params[:images].each do |image|
@room.photos.create!(image: image)
end
end
@photos = @room.photos
redirect_to edit_room_path(@room), notice: 'Saved...'
else
render :new
end
end
您还可以尝试删除styles键,以查看生成其他图像是否有问题,可能是ImageMagick未安装。问题已解决。我必须升级ImageMagick。谢谢大家尽量不要使用path。或者在任务的某个地方调试
<%= file_field_tag "images[]", type: :file, multiple: true %>
def create
@room = current_user.rooms.build(room_params)
if @room.save
if params[:images]
params[:images].each do |image|
@room.photos.create(image: image)
end
end
@photos = @room.photos
redirect_to edit_room_path(@room), notice: 'Saved...'
else
render :new
end
end
def create
@room = current_user.rooms.build(room_params)
if @room.save
if params[:images]
params[:images].each do |image|
@room.photos.create!(image: image)
end
end
@photos = @room.photos
redirect_to edit_room_path(@room), notice: 'Saved...'
else
render :new
end
end