Ruby on rails 上传回形针宝石时遇到问题
我在使用回形针宝石时遇到问题,当我选择图像文件并单击“提交”时,图像文件无法通过,我必须再次选择文件图像。所以基本上我上传图像时遇到了问题,我需要帮助 命令行rails服务器Ruby on rails 上传回形针宝石时遇到问题,ruby-on-rails,ruby,Ruby On Rails,Ruby,我在使用回形针宝石时遇到问题,当我选择图像文件并单击“提交”时,图像文件无法通过,我必须再次选择文件图像。所以基本上我上传图像时遇到了问题,我需要帮助 命令行rails服务器 new.html.erb {:multipart=>true}do | f |%> message.rb 类消息{:medium=>“700x500>”,:small=>“350x250>”},:default\url=>“/images/:style/missing.png” 验证\u附件\u内容\u类型:图像,
new.html.erb
{:multipart=>true}do | f |%>
message.rb
类消息{:medium=>“700x500>”,:small=>“350x250>”},:default\url=>“/images/:style/missing.png”
验证\u附件\u内容\u类型:图像,:内容\u类型=>/\Aimage\/.\Z/
结束
消息\u controller.rb
class messages控制器
(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