diff --git a/.gitignore b/.gitignore index 25a742d..b2d98d8 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,9 @@ # Ignore all logfiles and tempfiles. /log/*.log /tmp + +# Ignore file uploads +public/uploads + +# Ignore application configuration +/config/application.yml diff --git a/Gemfile b/Gemfile index 6f8c763..dabbea9 100644 --- a/Gemfile +++ b/Gemfile @@ -39,6 +39,11 @@ end gem 'devise' +gem 'carrierwave' +gem 'rmagick' # You should know where gems should go by now! +gem 'figaro' +gem "fog", "~> 1.3.1" # This is the version Fog that Carrierwave recommends at the time of this writing + # Use ActiveModel has_secure_password # gem 'bcrypt-ruby', '~> 3.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index af8e247..0a16e80 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,6 +29,10 @@ GEM atomic (1.1.14) bcrypt-ruby (3.1.2) builder (3.1.4) + carrierwave (0.9.0) + activemodel (>= 3.2.0) + activesupport (>= 3.2.0) + json (>= 1.7) coderay (1.0.9) coffee-rails (4.0.0) coffee-script (>= 2.2.0) @@ -44,7 +48,22 @@ GEM thread_safe (~> 0.1) warden (~> 1.2.3) erubis (2.7.0) + excon (0.13.4) execjs (2.0.2) + figaro (0.7.0) + bundler (~> 1.0) + rails (>= 3, < 5) + fog (1.3.1) + builder + excon (~> 0.13.0) + formatador (~> 0.2.0) + mime-types + multi_json (~> 1.0) + net-scp (~> 1.0.4) + net-ssh (>= 2.1.3) + nokogiri (~> 1.5.0) + ruby-hmac + formatador (0.2.4) haml (4.0.3) tilt haml-rails (0.4) @@ -68,6 +87,10 @@ GEM mime-types (1.25) minitest (4.7.5) multi_json (1.8.1) + net-scp (1.0.4) + net-ssh (>= 1.99.1) + net-ssh (2.7.0) + nokogiri (1.5.10) orm_adapter (0.4.0) polyglot (0.3.3) pry (0.9.12.2) @@ -93,6 +116,8 @@ GEM rake (10.1.0) rdoc (3.12.2) json (~> 1.4) + rmagick (2.13.2) + ruby-hmac (0.4.0) sass (3.2.12) sass-rails (4.0.0) railties (>= 4.0.0.beta, < 5.0) @@ -132,14 +157,18 @@ PLATFORMS ruby DEPENDENCIES + carrierwave coffee-rails (~> 4.0.0) devise + figaro + fog (~> 1.3.1) haml haml-rails jbuilder (~> 1.2) jquery-rails pry rails (= 4.0.0) + rmagick sass-rails (~> 4.0.0) sdoc sqlite3 diff --git a/app/models/post.rb b/app/models/post.rb index 8ddedb0..af83541 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -5,6 +5,8 @@ class Post < ActiveRecord::Base default_scope order('created_at DESC') before_save :set_defaults + mount_uploader :attachment, ImageUploader + private def set_defaults diff --git a/app/uploaders/image_uploader.rb b/app/uploaders/image_uploader.rb new file mode 100644 index 0000000..80c94ed --- /dev/null +++ b/app/uploaders/image_uploader.rb @@ -0,0 +1,56 @@ +# encoding: utf-8 + +class ImageUploader < CarrierWave::Uploader::Base + + # Include RMagick or MiniMagick support: + include CarrierWave::RMagick + # include CarrierWave::MiniMagick + + # Choose what kind of storage to use for this uploader: + # storage :file + storage :fog + + # Override the directory where uploaded files will be stored. + # This is a sensible default for uploaders that are meant to be mounted: + def store_dir + "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" + end + + # Provide a default URL as a default if there hasn't been a file uploaded: + # def default_url + # # For Rails 3.1+ asset pipeline compatibility: + # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) + # + # "/images/fallback/" + [version_name, "default.png"].compact.join('_') + # end + + # Process files as they are uploaded: + # process :scale => [200, 300] + # + # def scale(width, height) + # # do something + # end + + # Create different versions of your uploaded files: + version :thumb do + # process :scale => [50, 50] + process :resize_to_fit [75, 75] + end + + version :medium do + process :resize_to_fit [800, 800] + end + + # Add a white list of extensions which are allowed to be uploaded. + # For images you might use something like this: + # def extension_white_list + # %w(jpg jpeg gif png) + # end + + # Override the filename of the uploaded files: + # Avoid using model.id or version_name here, see uploader/store.rb for details. + # def filename + # "something.jpg" if original_filename + # end + +end diff --git a/app/views/projects/posts/_index.html.haml b/app/views/projects/posts/_index.html.haml index ab36f6c..0889363 100644 --- a/app/views/projects/posts/_index.html.haml +++ b/app/views/projects/posts/_index.html.haml @@ -4,11 +4,12 @@ - @posts.each do |post| .row - .large-2.columns + .small-2.columns = image_tag post.user.profile_pic - %p= post.user.name - .large-10.columns + %p= post.user.name? ? post.user.name : "Anonymous" + .small-10.columns %b= link_to post.title, project_url(@project.id, page: 'show', phase: @show_phase.name, post_id: post.id) %small= post.updated_at.strftime("%m/%d/%y at %I:%M%P") = if post.attachment? then image_tag 'https://s3.amazonaws.com/mks_learn_app/paperclip.png', width: '12px' end %p= post.message.truncate(300) + =if post.attachment? then image_tag post.attachment_url(:thumb) end diff --git a/app/views/projects/posts/_new.html.haml b/app/views/projects/posts/_new.html.haml index aa8d14f..4696a0e 100644 --- a/app/views/projects/posts/_new.html.haml +++ b/app/views/projects/posts/_new.html.haml @@ -8,7 +8,7 @@ .field = f.text_area :message, placeholder: "Type your message..." .field - = f.text_field :attachment, rows: 1, style: 'width: 90%;', placeholder: "Paste your attachment..." + = f.file_field :attachment, rows: 1, style: 'width: 90%;', placeholder: "Paste your attachment..." = f.hidden_field :project_id, value: @project.id = f.hidden_field :phase_id, value: params[:phase] diff --git a/app/views/projects/posts/_show.html.haml b/app/views/projects/posts/_show.html.haml index 4c1de44..76751f5 100644 --- a/app/views/projects/posts/_show.html.haml +++ b/app/views/projects/posts/_show.html.haml @@ -3,4 +3,4 @@ - if @post.attachment == "" no attachment available -else - %iframe{height: "800", width:"100%", frameBorder: "0", src: @post.attachment} \ No newline at end of file + %iframe{height: "800", width:"100%", frameBorder: "0", src: @post.attachment_url(:medium)} \ No newline at end of file diff --git a/config/initializers/carrierwave.rb b/config/initializers/carrierwave.rb new file mode 100644 index 0000000..62093b4 --- /dev/null +++ b/config/initializers/carrierwave.rb @@ -0,0 +1,8 @@ +CarrierWave.configure do |config| + config.fog_credentials = { + provider: "AWS", + aws_access_key_id: ENV['AS3_ACCESS_KEY'], + aws_secret_access_key: ENV['AS3_SECRET_ACCESS_KEY'] + } + config.fog_directory = ENV['AS3_BUCKET_NAME'] +end \ No newline at end of file