Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Day2start #2

Open
wants to merge 10 commits into
base: day2start
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp

# Ignore file uploads
public/uploads

# Ignore application configuration
/config/application.yml
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
29 changes: 29 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 56 additions & 0 deletions app/uploaders/image_uploader.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions app/views/projects/posts/_index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/views/projects/posts/_new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion app/views/projects/posts/_show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
- if @post.attachment == ""
no attachment available
-else
%iframe{height: "800", width:"100%", frameBorder: "0", src: @post.attachment}
%iframe{height: "800", width:"100%", frameBorder: "0", src: @post.attachment_url(:medium)}
8 changes: 8 additions & 0 deletions config/initializers/carrierwave.rb
Original file line number Diff line number Diff line change
@@ -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