Skip to content

Commit

Permalink
Commit 5. - Finished I4 of tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
BorisJov committed Aug 9, 2017
1 parent 5310169 commit f121350
Show file tree
Hide file tree
Showing 13 changed files with 358 additions and 106 deletions.
5 changes: 5 additions & 0 deletions .idea/Blogger.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

376 changes: 273 additions & 103 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ gem 'jbuilder', '~> 2.5'
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Paperclip for file storing
gem "paperclip"

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
Expand Down
11 changes: 11 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ GEM
xpath (~> 2.0)
childprocess (0.7.1)
ffi (~> 1.0, >= 1.0.11)
climate_control (0.2.0)
cocaine (0.5.8)
climate_control (>= 0.0.3, < 1.0)
coffee-rails (4.2.2)
coffee-script (>= 2.2.0)
railties (>= 4.0.0)
Expand Down Expand Up @@ -82,12 +85,19 @@ GEM
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mimemagic (0.3.2)
mini_portile2 (2.2.0)
minitest (5.10.3)
multi_json (1.12.1)
nio4r (2.1.0)
nokogiri (1.8.0)
mini_portile2 (~> 2.2.0)
paperclip (5.1.0)
activemodel (>= 4.2.0)
activesupport (>= 4.2.0)
cocaine (~> 0.5.5)
mime-types
mimemagic (~> 0.3.0)
public_suffix (2.0.5)
puma (3.9.1)
rack (2.0.3)
Expand Down Expand Up @@ -179,6 +189,7 @@ DEPENDENCIES
coffee-rails (~> 4.2)
jbuilder (~> 2.5)
listen (>= 3.0.5, < 3.2)
paperclip
puma (~> 3.7)
rails (~> 5.1.2)
sass-rails (~> 5.0)
Expand Down
36 changes: 36 additions & 0 deletions app/assets/stylesheets/styles.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
$primary_color: #d8daee;

body {
background-color: $primary_color;
font: {
family: Verdana, Helvetica, Arial;
size: 14px;
}
}

a {
color: #0000FF;
img {
border: none;
}
}

.clear {
clear: both;
height: 0;
overflow: hidden;
}

#container {
width: 75%;
margin: 0 auto;
background: #fff;
padding: 20px 40px;
border: solid 1px black;
margin-top: 20px;
}

#content {
clear: both;
padding-top: 20px;
}
2 changes: 1 addition & 1 deletion app/helpers/articles_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ArticlesHelper

def article_params
params.require(:article).permit(:title, :body, :tag_list)
params.require(:article).permit(:title, :body, :tag_list, :image)
end

end
2 changes: 2 additions & 0 deletions app/models/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ class Article < ApplicationRecord
has_many :comments
has_many :taggings
has_many :tags, through: :taggings
has_attached_file :image
validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png"]

def tag_list
tags.join(', ')
Expand Down
7 changes: 7 additions & 0 deletions app/views/articles/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
<%= f.label :body %> <br />
<%= f.text_area :body %>
</p>
<p>
<% if @article.image.exists? %>
<%= image_tag @article.image.url %></br>
<% end %>
<%= f.label :image, "Attach an image" %><br/>
<%= f.file_field :image %>
</p>
<p>
<%= f.label :tag_list %><br/>
<%= f.text_field :tag_list %>
Expand Down
5 changes: 5 additions & 0 deletions app/views/articles/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
<%= link_to tag.name, tag_path(tag) %>
<% end %>
</p>
<p>
<% if @article.image.exists? %>
<%= image_tag @article.image.url %>
<% end %>
</p>
<p><%= @article.body %></p>

<%= link_to 'Edit Article', edit_article_path(@article) %>
Expand Down
4 changes: 3 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
</head>

<body>
<p class="flash"><%= flash.notice %></p>
<p class="flash">
<%= flash.notice %>
</p>

<%= yield %>
</body>
Expand Down
8 changes: 8 additions & 0 deletions db/migrate/20170809163449_add_paperclip_fields_to_article.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class AddPaperclipFieldsToArticle < ActiveRecord::Migration[5.1]
def change
add_column :articles, :image_file_name, :string
add_column :articles, :image_content_type, :string
add_column :articles, :image_file_size, :integer
add_column :articles, :image_updated_at, :datetime
end
end
6 changes: 5 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170807120429) do
ActiveRecord::Schema.define(version: 20170809163449) do

create_table "articles", force: :cascade do |t|
t.string "title"
t.text "body"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
end

create_table "comments", force: :cascade do |t|
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f121350

Please sign in to comment.