Rails 4.0.4 and Mongoid(MongoDB)
- gem "mongoid-paperclip", "~> 0.0.8", :require => "mongoid_paperclip"
- gem "aws-s3", :require => "aws/s3"
*bundle install
you don't need to add the amazon web services gem at the moment, but you may need it later during production to store images
include Mongoid::Paperclip
Include in Photo model
belongs_to :your_model_that_photos_belong_to has_mongoid_attached_file :image validates_attachment_content_type :image, content_type: ["image/jpg", "image/jpeg", "image/png", "image/gif"]
Include in your model (below I reference your_model_name)
has_mongoid_attached_file :image validates_attachment_content_type :image, content_type: ["image/jpg", "image/jpeg", "image/png", "image/gif"]
- Add :image to the params of that controller to enable it to accept an uploaded file in the view
In your view for that model (wherever you would like the user to be able upload the image (index, show, new))
New
<%= form_for @photo, {url: photos_path(@photo)} do |f| %> <%= f.file_field :image %> <%= f.submit "Upload" %> <% end %>
New
<%= form_for @your_model_name do |f| %> <%= f.file_field :image %> <%= f.submit "Upload" %> <% end %>
Show
<%= image_tag @your_model_name.image.url %>
Let me know if something is not working or you see something that needs to be changed!