Skip to content

Commit 37c4d0d

Browse files
committed
Merge pull request #6 from morinpic/feature/blog
BLOG機能実装
2 parents c4e3853 + f2c57f1 commit 37c4d0d

File tree

20 files changed

+264
-17
lines changed

20 files changed

+264
-17
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ gem 'aws-sdk', '< 2.0'
4444
gem 'compass-rails', '~> 2.0.4'
4545
gem 'slim-rails', '~> 3.0.1'
4646

47+
gem 'ckeditor'
48+
4749
group :development, :test do
4850
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
4951
gem 'byebug'

Gemfile.lock

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ GEM
4949
byebug (5.0.0)
5050
columnize (= 0.9.0)
5151
chunky_png (1.3.4)
52+
ckeditor (4.1.2)
53+
cocaine
54+
orm_adapter (~> 0.5.0)
5255
climate_control (0.0.3)
5356
activesupport (>= 3.0)
5457
cocaine (0.5.7)
@@ -87,7 +90,7 @@ GEM
8790
warden (~> 1.2.3)
8891
erubis (2.7.0)
8992
execjs (2.5.2)
90-
ffi (1.9.8)
93+
ffi (1.9.9)
9194
foundation-icons-sass-rails (3.0.0)
9295
railties (>= 3.1.1)
9396
sass-rails (>= 3.1.1)
@@ -96,12 +99,6 @@ GEM
9699
sass (>= 3.3.0, < 3.5)
97100
globalid (0.3.5)
98101
activesupport (>= 4.1.0)
99-
haml (4.0.6)
100-
tilt
101-
haml2slim (0.4.7)
102-
haml (>= 3.0)
103-
nokogiri
104-
ruby_parser
105102
hike (1.2.3)
106103
hirb (0.7.3)
107104
hirb-unicode (0.0.5)
@@ -174,8 +171,6 @@ GEM
174171
rdoc (4.2.0)
175172
responders (2.1.0)
176173
railties (>= 4.2.0, < 5)
177-
ruby_parser (3.7.0)
178-
sexp_processor (~> 4.1)
179174
sass (3.4.15)
180175
sass-rails (5.0.1)
181176
railties (>= 4.0.0, < 5.0)
@@ -189,7 +184,6 @@ GEM
189184
seed-fu (2.3.5)
190185
activerecord (>= 3.1, < 4.3)
191186
activesupport (>= 3.1, < 4.3)
192-
sexp_processor (4.6.0)
193187
simple_form (3.1.0)
194188
actionpack (~> 4.0)
195189
activemodel (~> 4.0)
@@ -203,7 +197,7 @@ GEM
203197
railties (>= 3.1, < 5.0)
204198
slim (~> 3.0)
205199
spring (1.3.6)
206-
sprockets (2.12.3)
200+
sprockets (2.12.4)
207201
hike (~> 1.2)
208202
multi_json (~> 1.0)
209203
rack (~> 1.0)
@@ -239,12 +233,12 @@ PLATFORMS
239233
DEPENDENCIES
240234
aws-sdk (< 2.0)
241235
byebug
236+
ckeditor
242237
coffee-rails (~> 4.1.0)
243238
compass-rails (~> 2.0.4)
244239
devise (~> 3.5.1)
245240
foundation-icons-sass-rails
246241
foundation-rails
247-
haml2slim (~> 0.4.7)
248242
hirb (~> 0.7.3)
249243
hirb-unicode (~> 0.0.5)
250244
jbuilder (~> 2.0)

app/assets/javascripts/application.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
//= require jquery
1414
//= require jquery_ujs
1515
//= require foundation
16-
//= require turbolinks
16+
//#= require turbolinks
17+
//= require ckeditor/init
1718
//= require_tree .
1819

1920
$(function(){ $(document).foundation(); });
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
class PostsController < ApplicationController
2+
before_action :set_post, only: [:show, :edit, :update, :destroy]
3+
4+
def index
5+
@posts = Post.all
6+
end
7+
8+
def show
9+
end
10+
11+
def new
12+
@post = current_user.created_posts.build
13+
end
14+
15+
def edit
16+
end
17+
18+
def create
19+
@post = current_user.created_posts.build(post_params)
20+
if @post.save
21+
redirect_to @post, notice: '作成しました'
22+
else
23+
render :new
24+
end
25+
end
26+
27+
def update
28+
if @post.update(post_params)
29+
redirect_to @post, notice: '更新しました'
30+
else
31+
render :edit
32+
end
33+
end
34+
35+
def destroy
36+
@post.destroy!
37+
redirect_to posts_path, notice: '削除しました'
38+
end
39+
40+
private
41+
def set_post
42+
@post = current_user.created_posts.find(params[:id])
43+
end
44+
45+
def post_params
46+
params.require(:post).permit(:title, :body)
47+
end
48+
end

app/models/ckeditor/asset.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Ckeditor::Asset < ActiveRecord::Base
2+
include Ckeditor::Orm::ActiveRecord::AssetBase
3+
include Ckeditor::Backend::Paperclip
4+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Ckeditor::AttachmentFile < Ckeditor::Asset
2+
has_attached_file :data,
3+
:url => "/system/ckeditor_assets/attachments/:id/:filename",
4+
:path => ":rails_root/public/system/ckeditor_assets/attachments/:id/:filename"
5+
6+
validates_attachment_presence :data
7+
validates_attachment_size :data, :less_than => 100.megabytes
8+
do_not_validate_attachment_file_type :data
9+
10+
def url_thumb
11+
@url_thumb ||= Ckeditor::Utils.filethumb(filename)
12+
end
13+
end

app/models/ckeditor/picture.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Ckeditor::Picture < Ckeditor::Asset
2+
has_attached_file :data,
3+
:url => "/system/ckeditor_assets/pictures/:id/:style_:basename.:extension",
4+
:path => ":rails_root/public/system/ckeditor_assets/pictures/:id/:style_:basename.:extension",
5+
:styles => { :content => '800>', :thumb => '118x100#' }
6+
7+
validates_attachment_presence :data
8+
validates_attachment_size :data, :less_than => 2.megabytes
9+
validates_attachment_content_type :data, :content_type => /\Aimage/
10+
11+
def url_content
12+
url(:content)
13+
end
14+
end

app/models/post.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Post < ActiveRecord::Base
2+
belongs_to :owner, class_name: 'User'
3+
validates :title, :body, presence: true
4+
end

app/models/user.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
class User < ActiveRecord::Base
22
# Include default devise modules. Others available are:
33
# :confirmable, :lockable, :timeoutable and :omniauthable
4-
has_many :created_events, class_name: 'Event', foreign_key: :owner_id
5-
64
devise :database_authenticatable, :registerable,
75
:recoverable, :rememberable, :trackable, :validatable
86

7+
has_many :created_events, class_name: 'Event', foreign_key: :owner_id
8+
has_many :created_posts, class_name: 'Post', foreign_key: :owner_id
9+
910
has_attached_file :avatar,
1011
:styles => {
1112
:s => "200x200#",

app/views/posts/_form.html.slim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
= simple_form_for @post do |f|
2+
= f.error_notification
3+
4+
.field
5+
= f.input :title
6+
= f.cktext_area :body
7+
.form-actions
8+
= f.button :submit, '作成', data: { disable_with: '作成中...' }

0 commit comments

Comments
 (0)