diff --git a/.idea/Blogger.iml b/.idea/Blogger.iml
index b9aeeb4..49e9ce6 100644
--- a/.idea/Blogger.iml
+++ b/.idea/Blogger.iml
@@ -36,9 +36,12 @@
+
+
+
@@ -55,11 +58,13 @@
+
+
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 935e168..4ec9276 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,13 +2,15 @@
+
+
+
-
-
+
@@ -31,48 +33,98 @@
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -89,21 +141,23 @@
-
-
-
-
-
+
+
+
+
+
+
+
@@ -137,8 +191,6 @@
-
-
@@ -151,6 +203,12 @@
+
+
+
+
+
+
@@ -223,6 +281,8 @@
+
+
@@ -385,14 +445,17 @@
+
+
-
+
+
@@ -450,121 +513,149 @@
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
+
-
+
-
-
+
+
-
+
-
-
+
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
-
+
-
-
+
+
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -572,7 +663,6 @@
-
@@ -580,7 +670,6 @@
-
@@ -588,7 +677,6 @@
-
@@ -596,7 +684,6 @@
-
@@ -612,15 +699,6 @@
-
-
-
-
-
-
-
-
-
@@ -628,7 +706,6 @@
-
@@ -636,7 +713,6 @@
-
@@ -644,7 +720,6 @@
-
@@ -652,15 +727,6 @@
-
-
-
-
-
-
-
-
-
@@ -674,7 +740,7 @@
-
+
@@ -683,15 +749,119 @@
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Gemfile b/Gemfile
index 3029481..8bb1476 100644
--- a/Gemfile
+++ b/Gemfile
@@ -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
diff --git a/Gemfile.lock b/Gemfile.lock
index 5197a69..30255f9 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -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)
@@ -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)
@@ -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)
diff --git a/app/assets/stylesheets/styles.css.scss b/app/assets/stylesheets/styles.css.scss
new file mode 100644
index 0000000..c0a3656
--- /dev/null
+++ b/app/assets/stylesheets/styles.css.scss
@@ -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;
+}
\ No newline at end of file
diff --git a/app/helpers/articles_helper.rb b/app/helpers/articles_helper.rb
index 20ebc18..697a7c8 100644
--- a/app/helpers/articles_helper.rb
+++ b/app/helpers/articles_helper.rb
@@ -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
diff --git a/app/models/article.rb b/app/models/article.rb
index c779b31..9967669 100644
--- a/app/models/article.rb
+++ b/app/models/article.rb
@@ -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(', ')
diff --git a/app/views/articles/_form.html.erb b/app/views/articles/_form.html.erb
index 50c70cf..b91c552 100644
--- a/app/views/articles/_form.html.erb
+++ b/app/views/articles/_form.html.erb
@@ -12,6 +12,13 @@
<%= f.label :body %>
<%= f.text_area :body %>
+
+ <% if @article.image.exists? %>
+ <%= image_tag @article.image.url %>
+ <% end %>
+ <%= f.label :image, "Attach an image" %>
+ <%= f.file_field :image %>
+
<%= f.label :tag_list %>
<%= f.text_field :tag_list %>
diff --git a/app/views/articles/show.html.erb b/app/views/articles/show.html.erb
index d2eaf3a..0033eff 100644
--- a/app/views/articles/show.html.erb
+++ b/app/views/articles/show.html.erb
@@ -5,6 +5,11 @@
<%= link_to tag.name, tag_path(tag) %>
<% end %>
+
+ <% if @article.image.exists? %>
+ <%= image_tag @article.image.url %>
+ <% end %>
+
<%= @article.body %>
<%= link_to 'Edit Article', edit_article_path(@article) %>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 1e87981..46fa9f6 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -9,7 +9,9 @@
- <%= flash.notice %>
+
+ <%= flash.notice %>
+
<%= yield %>
diff --git a/db/migrate/20170809163449_add_paperclip_fields_to_article.rb b/db/migrate/20170809163449_add_paperclip_fields_to_article.rb
new file mode 100644
index 0000000..4b2cb54
--- /dev/null
+++ b/db/migrate/20170809163449_add_paperclip_fields_to_article.rb
@@ -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
diff --git a/db/schema.rb b/db/schema.rb
index 1700316..7b23405 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -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|
diff --git a/public/system/articles/images/000/000/015/original/beast.png b/public/system/articles/images/000/000/015/original/beast.png
new file mode 100644
index 0000000..99e4fd6
Binary files /dev/null and b/public/system/articles/images/000/000/015/original/beast.png differ