Skip to content

Commit

Permalink
initial image upload commit. carrierwave, thumb version
Browse files Browse the repository at this point in the history
  • Loading branch information
jeloi committed Nov 24, 2013
1 parent b011369 commit bccb3de
Show file tree
Hide file tree
Showing 34 changed files with 185 additions and 46 deletions.
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ gem 'bootstrap-will_paginate'
gem 'cancan'
gem 'nokogiri'
gem 'acts_as_commentable'
gem 'carrierwave'
gem 'rmagick'
gem 'fog'
gem 'carrierwave_direct'
gem 'sidekiq'


# gem 'jquery-turbolinks'

Expand Down
43 changes: 43 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ GEM
capybara-webkit (1.0.0)
capybara (~> 2.0, >= 2.0.2)
json
carrierwave (0.9.0)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
json (>= 1.7)
carrierwave_direct (0.0.13)
carrierwave
fog
uuidtools
celluloid (0.15.2)
timers (~> 1.1.0)
childprocess (0.3.6)
ffi (~> 1.0, >= 1.0.6)
chosen-rails (1.0.1)
Expand All @@ -72,6 +82,7 @@ GEM
chunky_png (~> 1.2)
fssm (>= 0.2.7)
sass (~> 3.1)
connection_pool (1.1.0)
cucumber (1.3.6)
builder (>= 2.1.2)
diff-lcs (>= 1.1.3)
Expand All @@ -85,6 +96,7 @@ GEM
database_cleaner (1.0.1)
diff-lcs (1.2.4)
erubis (2.7.0)
excon (0.28.0)
execjs (2.0.1)
factory_girl (4.2.0)
activesupport (>= 3.0.0)
Expand All @@ -96,6 +108,16 @@ GEM
faraday (0.8.8)
multipart-post (~> 1.2.0)
ffi (1.9.0)
fog (1.18.0)
builder
excon (~> 0.28.0)
formatador (~> 0.2.0)
mime-types
multi_json (~> 1.0)
net-scp (~> 1.1)
net-ssh (>= 2.1.3)
nokogiri (~> 1.5)
ruby-hmac
formatador (0.2.4)
friendly_id (5.0.0.beta4)
activerecord (~> 4.0.0)
Expand Down Expand Up @@ -145,6 +167,9 @@ GEM
multi_test (0.0.2)
multipart-post (1.2.0)
mysql2 (0.3.13)
net-scp (1.1.2)
net-ssh (>= 2.6.5)
net-ssh (2.7.0)
nokogiri (1.6.0)
mini_portile (~> 0.5.0)
oauth2 (0.8.1)
Expand Down Expand Up @@ -198,6 +223,10 @@ GEM
ffi (>= 0.5.0)
rdoc (3.12.2)
json (~> 1.4)
redis (3.0.6)
redis-namespace (1.3.2)
redis (~> 3.0.4)
rmagick (2.13.2)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
Expand All @@ -213,6 +242,7 @@ GEM
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
ruby-hmac (0.4.0)
rubyzip (0.9.9)
sass (3.2.10)
sass-rails (4.0.0.rc2)
Expand All @@ -233,6 +263,12 @@ GEM
shoulda-context (1.1.5)
shoulda-matchers (2.3.0)
activesupport (>= 3.0.0)
sidekiq (2.16.1)
celluloid (>= 0.15.2)
connection_pool (>= 1.0.0)
json
redis (>= 3.0.4)
redis-namespace (>= 1.3.1)
slop (3.4.6)
sprockets (2.10.0)
hike (~> 1.2)
Expand All @@ -249,6 +285,7 @@ GEM
thread_safe (0.1.2)
atomic
tilt (1.4.1)
timers (1.1.0)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
Expand All @@ -258,6 +295,7 @@ GEM
uglifier (2.1.1)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
uuidtools (2.1.4)
websocket (1.0.7)
will_paginate (3.0.4)
xpath (2.0.0)
Expand All @@ -278,6 +316,8 @@ DEPENDENCIES
cancan
capybara
capybara-webkit
carrierwave
carrierwave_direct
childprocess (= 0.3.6)
chosen-rails
coffee-rails (= 4.0.0)
Expand All @@ -286,6 +326,7 @@ DEPENDENCIES
database_cleaner (= 1.0.1)
factory_girl_rails
faker
fog
friendly_id (= 5.0.0.beta4)
guard-rspec
guard-zeus
Expand All @@ -300,11 +341,13 @@ DEPENDENCIES
quiet_assets
rails (= 4.0.0)
rails_12factor
rmagick
rspec-rails
sass-rails (= 4.0.0.rc2)
sdoc (= 0.3.20)
selenium-webdriver
shoulda
sidekiq
sqlite3 (= 1.3.7)
terminal-notifier-guard
turbolinks (= 1.1.1)
Expand Down
Binary file added app/.DS_Store
Binary file not shown.
Binary file added app/assets/.DS_Store
Binary file not shown.
Binary file modified app/assets/images/.DS_Store
Binary file not shown.
Binary file added app/assets/images/logo1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 20 additions & 5 deletions app/assets/stylesheets/recipes.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
position: relative;
display: table;
width: 100%;
.recipe-image {

}
}

.recipe-info {
Expand Down Expand Up @@ -155,6 +158,12 @@
width: 100%;
}

.top-show-section {
background: white;
min-height: 240px;
margin-bottom: 15px;
}

.recipe-info {
padding: 0 10%;
display: table-cell;
Expand All @@ -165,11 +174,17 @@
font-size: 2.5em;
}
}

.top-show-section {
background: white;
min-height: 240px;
margin-bottom: 15px;
.recipe-image {
width: 240px;
background: blue;
img {
background: blue;
// width: 100%;
// height: 100%;
vertical-align: top;
display: block;
}
}

}

12 changes: 7 additions & 5 deletions app/assets/stylesheets/visual.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ header#header {
background: #DAEFF8;
margin: 0 auto;
text-align: center;
border-bottom: 1px solid #dddddd;
overflow: auto;
a.logo {
margin: 15px 0;
Expand Down Expand Up @@ -79,12 +80,12 @@ nav.main-nav {
// background: $blue;
margin: 0 auto;
padding-bottom: 5px;
border-bottom: 1px solid #dddddd;
// border-bottom: 1px solid #dddddd;
ul {
max-width: 550px;
width: 100%;
display: block;
padding: 0px 10px ; margin: 0 auto;
margin: 0 auto;
overflow: hidden;
}

Expand Down Expand Up @@ -120,9 +121,10 @@ nav.main-nav {
}

.toolbar {
max-width: $main-width;
height: 7px;
background-color: $blue;
// max-width: $main-width;
height: 20px;
// background-color: #f6f6f6;
background-color: white;
// background-color: rgba(147, 208, 109, 0.64);
margin: 0 auto;
}
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/recipes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ def set_items

# Never trust parameters from the scary internet, only allow the white list through.
def recipe_params
params.require(:recipe).permit(:directions, :title, :blurb, :tag_list, ingredients_attributes: [:item_id, :quantity, :_destroy, :id], taggings_attributes: [:_destroy, :tag_id, :id])
params.require(:recipe).permit(:image, :directions, :title, :blurb, :tag_list, ingredients_attributes: [:item_id, :quantity, :_destroy, :id], taggings_attributes: [:_destroy, :tag_id, :id])
end
end
21 changes: 13 additions & 8 deletions app/models/recipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@
#
# Table name: recipes
#
# id :integer not null, primary key
# directions :text
# title :string(255)
# blurb :string(255)
# user_id :integer
# created_at :datetime
# updated_at :datetime
# slug :string(255)
# id :integer not null, primary key
# directions :text
# title :string(255)
# blurb :string(255)
# user_id :integer
# created_at :datetime
# updated_at :datetime
# slug :string(255)
# bites_count :integer default(0)
# favorites_count :integer default(0)
# comments_count :integer default(0)
# image :string(255)
#

class Recipe < ActiveRecord::Base
acts_as_commentable
extend FriendlyId
# Friendly_id gem use database slug
friendly_id :title, :use => :slugged
mount_uploader :image, ImageUploader

# Associations
belongs_to :user
Expand Down
Binary file added app/uploaders/.DS_Store
Binary file not shown.
60 changes: 60 additions & 0 deletions app/uploaders/image_uploader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 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]

process :auto_orient
#
# def scale(width, height)
# # do something
# end

# Create different versions of your uploaded files:
version :thumb do
process :resize_to_fill => [200, 200]
end

# Auto orient an image
def auto_orient
manipulate! do |img|
img = img.auto_orient
end
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
27 changes: 11 additions & 16 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<body id="<%= params[:controller] + '-' + params[:action] %>">
<div id="pagewrap">


<header id="header">
<%= link_to(root_path, class: "logo clrfix") do %>
<div class="header-logo"></div>
Expand All @@ -50,22 +50,17 @@
</form> -->

</header>
<nav class="main-nav">
<ul>
<li class="nav-1"><%= link_to "recipes", recipes_path, class: ("active" if params[:controller] == "recipes" and !current_page?(new_recipe_path)) %></li>
<li class="nav-2"><%= link_to "menus", menus_path, class: ("active" if params[:controller] == "pages" and params[:action] == "menus") %></li>
<li class="nav-3"><%= link_to "create", new_recipe_path, class: ("active" if current_page?(new_recipe_path)) %></li>
<li class="nav-4"><a href="">tags</a></li>
<li class="nav-5"><%= link_to "ingredients", all_items_path, class: ("active" if params[:controller] == "items") %></li>
</ul>
</nav>




<nav class="main-nav">
<ul>
<li class="nav-1"><%= link_to "recipes", recipes_path, class: ("active" if params[:controller] == "recipes" and !current_page?(new_recipe_path)) %></li>
<li class="nav-2"><%= link_to "menus", menus_path, class: ("active" if params[:controller] == "pages" and params[:action] == "menus") %></li>
<li class="nav-3"><%= link_to "create", new_recipe_path, class: ("active" if current_page?(new_recipe_path)) %></li>
<li class="nav-4"><a href="">tags</a></li>
<li class="nav-5"><%= link_to "ingredients", all_items_path, class: ("active" if params[:controller] == "items") %></li>
</ul>
</nav>
<!-- <div class="toolbar"></div> -->




<div id="body-section">
<div id="body-content">
Expand Down
4 changes: 2 additions & 2 deletions app/views/recipes/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="padded-wrap">
<h2><%= heading %></h2>

<%= form_for(@recipe) do |f| %>
<%= form_for @recipe, :html => {:multipart => true} do |f| %>
<% if @recipe.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@recipe.errors.count, "error") %> prohibited this recipe from being saved:</h2>
Expand Down Expand Up @@ -71,7 +71,7 @@
<% @tag_fields_content = add_fields_helper(f, :taggings) %>



<%= f.file_field :image %>
<%= f.submit submit_text, id: :create_recipe %>
<% end %>

Expand Down
Loading

0 comments on commit bccb3de

Please sign in to comment.