Add a validation rule for content_type pin.image#1
Add a validation rule for content_type pin.image#1bachbui wants to merge 1 commit intojsmollen2:masterfrom
Conversation
bachbui
commented
Feb 7, 2017
- Paperclip 4.0 requires a validation rule for file attachments
- Set this to accept common image types (jpg, png, gif)
- Paperclip 4.0 requires a validation rule for file attachments - Set this to accept common image types (jpg, png, gif)
| gem 'turbolinks', '~> 5' | ||
| gem 'jbuilder', '~> 2.5' | ||
| gem 'bootstrap-sass' | ||
| gem 'bootstrap-sass', '~> 3.2.0' |
There was a problem hiding this comment.
This makes your code more portable, as you need bootstrap 3 to run it. On systems that have an older version installed, your app will see that bootstrap is already installed but then will hit errors when it runs.
| class Pin < ActiveRecord::Base | ||
| belongs_to :user | ||
| has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" } | ||
| validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"] |
There was a problem hiding this comment.
This is the validation rule which checks that the file being uploaded has one of the standard image content-types, so that someone would be prevented from uploaded a pdf for example. You'd probably want to add additional validation rules, like on the max file size, for example.
| <p id="notice"><%= notice %></p> | ||
|
|
||
| <p> | ||
| <%= link_to image_tag(@pin.image.url, class: 'media-object'), @pin.image.url, target: '_blank' %> |
There was a problem hiding this comment.
This is just to test that the image upload was working. You'd probably want to display a thumbnail version of the image instead what this is doing, which is showing the original.