如果我尝试上传图片信息出现:
"New Content
1 error prohibited this content from being saved:
That cover has contents are not what they are reported to be "
然后显示“失踪”
在 Git Bash 中,出现:
"[Paperclip] Content Type Spoof: Filename goku.jpg (image / jpeg from Headers, [" image / jpeg "] from Extension), content type discovered from file command:. See documentation to allow this combination.
(0.0ms) begin transaction
Command :: -b --mime file "C: /Users/xxxxxx/AppData/Local/Temp/1151fe66500e3084eef890162322a11020170115-9100-1xumnlr.jpg"
[Paperclip] Content Type Spoof: Filename juegos-vestir-goku.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
Rendering contents / new.html.erb Within layouts / application
Rendered contents / _form.html.erb (4.0ms)
Rendered contents / new.html.erb Within layouts / application (30.0ms)
Rendered layouts / _header2.html.erb (2.0ms)
Rendered layouts / _footer.html.erb (0.0ms)
Completed 200 OK in 627ms (Views: 511.2ms | ActiveRecord: 0.0ms) "
此外,当我安装回形针时出现以下消息:
"Post-install message from paperclip:
##################################################
# NOTES FOR UPGRADING FROM 4.3.0 OR EARLIER #
##################################################
Paperclip is now compatible with aws-sdk> = 2.0.0.
If you are using S3 storage, aws-sdk> = 2.0.0 requires you to make a few small
changes:
* You must September the `s3_region`
* If you are Explicitly setting permissions anywhere, such as in an initializer,
notes That the format of the permissions changed from using an underscore to
using a hyphen. For example, `: public_read` needs to be changed to
`Public-read`.
For a walkthrough of upgrading from 4 to 5 and aws-sdk> = 2.0 you can watch
http://rubythursday.com/episodes/ruby-snack-27-upgrade-paperclip-and-aws-sdk-in-prep-for-rails-5 "
执行安装回形针的操作:
- Downloaded magemagick for windows
- Insert in Gemfile gem "paperclip", "~> 5.0.0"
- Bundle install
- In the app >> model >> content.rb I entered:
has_attached_file: cover, styles {medium: "300x>" thumb "100x>"}
validates_attachment_content_type: cover, content_type: /\Aimage\/.*\z/
- Rails generate paperclip content cover
- Rake db: migrate
- I added to my code in the app> views> contents> _form,:
<%= form_for @content, html: { multipart: true } do |f| %>
<Div class = "field">
<% = F.label: cover%>
<% = F.file_field: cover%>
</ Div>
- App> controllers> content, I entered:
def content_params
params.require (: content) .permit (: title: description: price,: cover)
end
- App> views> content> show I entered:
<% = @ Image_tag content.cover.url (: thumb)%>
- App> views> content> index> I entered:
<Td> <% = image_tag content.cover.url (: medium)%> </ td>
使用的版本:
-Win10 x64
-ruby 2.3.3p222
-Rails 5.0.1
-paperclip 5.1.0
进行了测试,但不是决定性的:
在 app> model> content.rb 中添加:
:default_url => "/images/:style/missing.png"
在 config/environments/development.rb 中添加:
Paperclip.options[:command_path] = "/usr/local/bin/"
Paperclip.options [: command_path] = 'C:\Program Files (x86)\GnuWin32\bin
添加在 - 添加在 app> model> content.rb 中:
Paperclip.options[:command_path] = 'C:\Program Files (x86)\GnuWin32\bin; C:\程序文件\ImageMagick-7.0.4-Q16'
Paperclip.options [:swallow_stderr] = false