Skip to content

Conversation

@bachbui
Copy link

@bachbui 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'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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' %>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant