我在使用paperclip gem时遇到问题,当我选择我的图像文件并单击提交时,图像文件没有通过,我必须再次选择文件图像。所以基本上我在使用paperclip gem上传图片时遇到了麻烦我需要帮助
(0.0ms) begin transaction
Command :: SET PATH=/usr/local/bin/;%PATH% & file -b --mime "C:/Users/Michael/AppData/Local/Temp/5664a0e0a6a4bd4baf3d5e2cecfcad5520170525-37656-wfezoi.jpg"
[paperclip] Content Type Spoof: Filename Mario_(Mario_Kart_Wii).jpg (image/jpeg from Headers, ["image/jpeg"] from Extension), content type discovered from file command: . See documentation to allow this combination.
(0.0ms) rollback transaction
<%= simple_form_for @message, :html => { :multipart => true } do |f| %>
<%= f.file_field :image %>
<%= f.input :title %>
<%= f.input :description %>
<%= f.button :submit %>
<% end %>
class Message < ApplicationRecord
belongs_to :user
has_many :comments
has_attached_file :image, :styles => { :medium => "700x500>", :small => "350x250>" } ,:default_url => "/images/:style/missing.png"
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
end
class MessagesController < ApplicationController
before_action :find_message, only: [:show, :edit, :update, :destroy]
def index
@messages = Message.all.order("created_at DESC")
end
def new
@message = current_user.messages.build
end
def create
@message = current_user.messages.build(message_params)
if @message.save
redirect_to root_path
else
render 'new'
end
end
def show
end
def update
if @message.update(message_params)
redirect_to message_path
else
render 'edit'
end
end
def edit
end
def destroy
@message.destroy
redirect_to root_path
end
def message_params
params.require(:message).permit(:title, :description, :image)
end
def find_message
@message = Message.find(params[:id])
end
end