likelion 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/lib/generators/likelion/USAGE +2 -1
  4. data/lib/generators/likelion/create_templates.rb +54 -5
  5. data/lib/generators/likelion/install_generator.rb +1 -0
  6. data/lib/generators/likelion/templates/160415/command.txt +2 -0
  7. data/lib/generators/likelion/templates/160415/create_posts.rb +11 -0
  8. data/lib/generators/likelion/templates/160415/home.index.html.erb +12 -0
  9. data/lib/generators/likelion/templates/160415/home.list.html.erb +11 -0
  10. data/lib/generators/likelion/templates/160415/home.update_view.html.erb +13 -0
  11. data/lib/generators/likelion/templates/160415/home.write.html.erb +2 -0
  12. data/lib/generators/likelion/templates/160415/home_controller.rb +21 -0
  13. data/lib/generators/likelion/templates/160415/routes.rb +9 -0
  14. data/lib/generators/likelion/templates/160415/views.txt +4 -0
  15. data/lib/generators/likelion/templates/160425/board.index.html.erb +32 -0
  16. data/lib/generators/likelion/templates/160425/board_controller.rb +25 -0
  17. data/lib/generators/likelion/templates/160425/command.txt +3 -0
  18. data/lib/generators/likelion/templates/160425/comment.rb +3 -0
  19. data/lib/generators/likelion/templates/160425/create_comments.rb +10 -0
  20. data/lib/generators/likelion/templates/160425/create_posts.rb +10 -0
  21. data/lib/generators/likelion/templates/160425/post.rb +3 -0
  22. data/lib/generators/likelion/templates/160425/routes.rb +9 -0
  23. data/lib/generators/likelion/templates/160425/views.txt +1 -0
  24. data/lib/generators/likelion/templates/160427/command.txt +3 -0
  25. data/lib/generators/likelion/templates/160427/create_posts.rb +10 -0
  26. data/lib/generators/likelion/templates/160427/create_replies.rb +10 -0
  27. data/lib/generators/likelion/templates/160427/home.index.html.erb +30 -0
  28. data/lib/generators/likelion/templates/160427/home_controller.rb +22 -0
  29. data/lib/generators/likelion/templates/160427/post.rb +4 -0
  30. data/lib/generators/likelion/templates/160427/readme +2 -0
  31. data/lib/generators/likelion/templates/160427/reply.rb +3 -0
  32. data/lib/generators/likelion/templates/160427/routes.rb +5 -0
  33. data/lib/generators/likelion/templates/160427/seeds.rb +18 -0
  34. data/lib/generators/likelion/templates/160427/views.txt +1 -0
  35. data/lib/generators/likelion/templates/160502/command.txt +3 -0
  36. data/lib/generators/likelion/templates/160502/create_posts.rb +10 -0
  37. data/lib/generators/likelion/templates/160502/create_replies.rb +10 -0
  38. data/lib/generators/likelion/templates/160502/home.index.html.erb +51 -0
  39. data/lib/generators/likelion/templates/160502/home_controller.rb +22 -0
  40. data/lib/generators/likelion/templates/160502/post.rb +4 -0
  41. data/lib/generators/likelion/templates/160502/readme +2 -0
  42. data/lib/generators/likelion/templates/160502/reply.rb +3 -0
  43. data/lib/generators/likelion/templates/160502/routes.rb +5 -0
  44. data/lib/generators/likelion/templates/160502/seeds.rb +18 -0
  45. data/lib/generators/likelion/templates/160502/views.txt +1 -0
  46. data/lib/generators/likelion/templates/160512/command.txt +1 -0
  47. data/lib/generators/likelion/templates/160512/home.index.html.erb +12 -0
  48. data/lib/generators/likelion/templates/160512/home_controller.rb +13 -0
  49. data/lib/generators/likelion/templates/160512/initializer.aws.rb +11 -0
  50. data/lib/generators/likelion/templates/160512/light_uploader.rb +53 -0
  51. data/lib/generators/likelion/templates/160512/readme +2 -0
  52. data/lib/generators/likelion/templates/160512/routes.rb +4 -0
  53. data/lib/generators/likelion/templates/160512/views.txt +1 -0
  54. data/lib/generators/likelion/templates/160525/command.txt +2 -0
  55. data/lib/generators/likelion/templates/160525/home_controller.rb +16 -0
  56. data/lib/generators/likelion/templates/160525/readme +3 -0
  57. data/lib/generators/likelion/templates/160525/seeds.rb +2 -0
  58. data/lib/generators/likelion/templates/160525/student.rb +14 -0
  59. data/lib/likelion/version.rb +1 -1
  60. metadata +55 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f5ebb93feabc10494cf074967fe9964f6da243bd
4
- data.tar.gz: c12e982ad6002c26076b50fda60c1b7da1db55dc
3
+ metadata.gz: fdeceeeb99c12a94863953f75aa5df46e5203ae7
4
+ data.tar.gz: 21625ddcb1ec518f699aa248c1c8f7244386db2b
5
5
  SHA512:
6
- metadata.gz: 8cbf55943ef32237e0215f32985ad768ab6be48ac32320d944b598f1f22c5f0052eae2dc1d655d93dafc70130893b7e181775a6939e1145b3981ea827c4b90ad
7
- data.tar.gz: fe3be5be5afb6ba14787d7b83f2b503c2407bc312596bc2c13f118715a1ab3860728c809d0ca71c85d83321d48a40335b3d2de7570e3289eb765915d5e06e78e
6
+ metadata.gz: fcfba2ed003cdc255a71532700f4c86a174749e90a2aff3e004399dec4bdb39552da2460f3464acb4ed717f29b9bbc05266fe55a6f4caffde5ecc75d83ff4ebd
7
+ data.tar.gz: 15668ca24287c162581ab910d16608ec98fb7fae8f98235bb0fadec87280eba5fe33b57090ef4db10d89f665e63e156c801f7387c22c0f49947e12457a3a6e65
data/README.md CHANGED
@@ -35,7 +35,7 @@ Gem을 설치한 후 아래와 같이 사용합니다.
35
35
  ...
36
36
  Description:
37
37
  현재 생성 가능한 날짜의 코드는
38
- [160408]
38
+ [160408, 160411, 160413, 160415, 160425, 160427, 160502, 160509]
39
39
  입니다.
40
40
 
41
41
  확인할 수 있습니다
@@ -162,7 +162,7 @@ create_templates::process에서 실행되며 순서는 아래와 같습니다.
162
162
 
163
163
  $ gem build likelion.gemspec
164
164
 
165
- 위 명령어를 입력하면 likelion-[VERSION].gem 이 생성됩니다. 2016년 5월 27일 기준으로 likelion-0.1.1.gem 이 생성됩니다. 새로운 rails application을 만들어 테스트해봅시다.
165
+ 위 명령어를 입력하면 likelion-[VERSION].gem 이 생성됩니다. 2016년 5월 27일 기준으로 likelion-0.2.0.gem 이 생성됩니다. 새로운 rails application을 만들어 테스트해봅시다.
166
166
 
167
167
  $ cd ..
168
168
  $ rails new blog
@@ -1,6 +1,7 @@
1
1
  Description:
2
2
  현재 생성 가능한 날짜의 코드는
3
- [160408, 160411]
3
+ [160408, 160411, 160413, 160415, 160425, 160427,
4
+ 160502, 160509, 160512]
4
5
  입니다.
5
6
 
6
7
  Example:
@@ -4,26 +4,43 @@ class CreateTemplates < Thor::Group
4
4
  include Thor::Actions
5
5
 
6
6
  raise ArgumentError, "The date should be input." if ARGV[0] == nil
7
- @@path = "#{File.dirname(__FILE__)}/templates/#{ARGV[0]}"
8
-
7
+ @@path = ""
8
+ #for aliasing
9
+ @@converter = { "검색" => "160525", "ajax" => "160502" }
10
+
11
+ def set_path
12
+ keyword = ARGV[0]
13
+ if @@converter.has_key?(keyword.rstrip.downcase)
14
+ keyword = @@converter[keyword]
15
+ end
16
+ @@path = "#{File.dirname(__FILE__)}/templates/#{keyword}"
17
+ end
18
+
9
19
  def self.source_root
10
20
  File.dirname(__FILE__)
11
21
  end
12
22
 
13
23
  def process
14
24
  source_paths << @@path
25
+ #키워드를 날짜로 변환
26
+ set_path
15
27
  #모델, 컨트롤러 등 생성
16
28
  run_commands
17
-
18
29
  #view 생성
19
30
  create_views
20
-
31
+ #initializer 파일 추가
32
+ add_initializer
21
33
  #application_controller.rb 주석 처리
22
34
  comment_application_controller
23
35
  #bootstrap 추가
24
36
  add_bootstraps
25
37
  #routes.rb 설정
26
38
  set_routes
39
+ #seed 추가
40
+ add_seeds
41
+
42
+ #완료 후 설명 출력
43
+ print_description
27
44
  end
28
45
 
29
46
  def run_commands
@@ -47,7 +64,6 @@ class CreateTemplates < Thor::Group
47
64
  end
48
65
  def add_attributes(line)
49
66
  #TODO : Devise는...?
50
- # Thor::Actions::inject_into_class
51
67
  line = line.split
52
68
  if line[2].eql?"controller"
53
69
  run(copy_file("#{@@path}/#{line[3]}_controller.rb", \
@@ -96,10 +112,16 @@ class CreateTemplates < Thor::Group
96
112
 
97
113
  def set_routes
98
114
  #routes.rb 내용을 복사
115
+ unless File.exist?("#{@@path}/routes.rb")
116
+ return
117
+ end
99
118
  run(copy_file("#{@@path}/routes.rb", "config/routes.rb"))
100
119
  end
101
120
 
102
121
  def create_views
122
+ unless File.exist?("#{@@path}/views.txt")
123
+ return
124
+ end
103
125
  File.open("#{@@path}/views.txt","r") do |infile|
104
126
  while(filename = infile.gets)
105
127
  filename.rstrip!
@@ -109,6 +131,33 @@ class CreateTemplates < Thor::Group
109
131
  end
110
132
  end
111
133
  end
134
+
135
+ def add_initializer
136
+ initializers = Dir["#{@@path}/initializer*"].select { |f| f =~ /initializer.*.rb$/ }
137
+ if initializers.empty?
138
+ return
139
+ end
140
+ initializers.each do |file|
141
+ file_name = file.split('.',2)[1]
142
+ run(copy_file(file, "config/initializers/#{file_name}"))
143
+ end
144
+ end
145
+ def add_seeds
146
+ #seeds.rb 내용을 복사
147
+ unless File.exist?("#{@@path}/seeds.rb")
148
+ return
149
+ end
150
+ run(copy_file("#{@@path}/seeds.rb", "config/seeds.rb"))
151
+ end
152
+
153
+ #설명 출력하기
154
+ def print_description
155
+ puts "================================"
156
+ if File.exist?("#{@@path}/readme")
157
+ puts File.read("#{@@path}/readme")
158
+ end
159
+ puts "================================"
160
+ end
112
161
  end
113
162
 
114
163
  CreateTemplates.new.process
@@ -2,6 +2,7 @@ module Likelion
2
2
  class InstallGenerator < Rails::Generators::NamedBase
3
3
  @@path = File.dirname(__FILE__)
4
4
  desc File.read("#{@@path}/USAGE")
5
+
5
6
  def copy_snippet
6
7
  run("ruby #{@@path}/create_templates.rb #{file_name}")
7
8
  end
@@ -0,0 +1,2 @@
1
+ rails g controller home index
2
+ rails g model post
@@ -0,0 +1,11 @@
1
+ class CreatePosts < ActiveRecord::Migration
2
+ def change
3
+ create_table :posts do |t|
4
+
5
+ t.string "title"
6
+ t.string "content"
7
+
8
+ t.timestamps null: false
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ <h1>hi</h1>
2
+ <div class="container">
3
+ <form action="/write" method="POST">
4
+ <div class="form-group">
5
+ <label for="exampleInputEmail1">제목</label>
6
+ <input type="text" name="title" class="form-control" id="exampleInputEmail1" placeholder="제목">
7
+ </div>
8
+ <label for="exampleInputEmail1">내용</label>
9
+ <textarea name="content" class="form-control" rows="5" id="commit"></textarea>
10
+ <button type="submit" class="btn btn-default" style="margin-top:20px">전송</button>
11
+ </form>
12
+ </div>
@@ -0,0 +1,11 @@
1
+ <h2>여기는 지난 게시판 글입니다.</h2>
2
+ <% @every_post.each do |p| %>
3
+ <%= p.title %>
4
+ <%= p.content %>
5
+ <%= p.created_at %>
6
+ <a href="/update_view/<%= p.id %>">[수정]</a>
7
+ <a href="/destroy/<%= p.id %>">[삭제]</a>
8
+
9
+ <hr>
10
+ <% end %>
11
+ <h1><a href="/">게시판 글 쓰러 가기</a></h1>
@@ -0,0 +1,13 @@
1
+ 여기는 수정하는 페이지 입니다.
2
+ <h1>hi</h1>
3
+ <div class="container">
4
+ <form action="/update/<%= @one_post.id %>" method="POST">
5
+ <div class="form-group">
6
+ <label for="exampleInputEmail1">제목</label>
7
+ <input type="text" name="title" value="<%=@one_post.title %>" class="form-control" id="exampleInputEmail1" placeholder="제목">
8
+ </div>
9
+ <label for="exampleInputEmail1">내용</label>
10
+ <textarea name="content" class="form-control" rows="5" id="commit"><%=@one_post.content %></textarea>
11
+ <button type="submit" class="btn btn-default" style="margin-top:20px">전송</button>
12
+ </form>
13
+ </div>
@@ -0,0 +1,2 @@
1
+ <%= @title %>
2
+ <%= @content %>
@@ -0,0 +1,21 @@
1
+ class HomeController < ApplicationController
2
+ def index
3
+ end
4
+
5
+ def write
6
+ @title = params[:title]
7
+ @content = params[:content]
8
+
9
+ new_post = Post.new
10
+ new_post.title = @title
11
+ new_post.content = @content
12
+ new_post.save
13
+
14
+ redirect_to "/list"
15
+
16
+ end
17
+
18
+ def list
19
+ @every_post = Post.all.order("id desc")
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ Rails.application.routes.draw do
2
+ root 'home#index'
3
+ get 'home/index'
4
+ post 'write' => "home#write"
5
+ get '/list' => "home#list"
6
+ get 'destroy/:post_id' => "home#destroy"
7
+ get 'update_view/:post_id' => "home#update_view"
8
+ post 'update/:post_id' => "home#update"
9
+ end
@@ -0,0 +1,4 @@
1
+ home.index.html.erb
2
+ home.list.html.erb
3
+ home.write.html.erb
4
+ home.update_view.html.erb
@@ -0,0 +1,32 @@
1
+ <div class="container">
2
+ <% @post.each do |post| %>
3
+ <%= post.title %></br>
4
+ <%= post.content %></br>
5
+ <%= post.created_at %></br>
6
+
7
+ <% post.comments.each do |c| %>
8
+ <%= c.id %> <%= c.content %><br>
9
+
10
+ <% end %>
11
+ <form action="/board/<%= post.id %>/comment_create" method="POST">
12
+ <div class="form-group">
13
+ <input type="text" name="content" class="form-control" placeholder="제목">
14
+ </div>
15
+ <button type="submit" class="btn btn-default">댓글달기</button>
16
+ </form>
17
+ <hr>
18
+
19
+ <% end %>
20
+ <hr><br>
21
+ <form action="/board/create" method="POST">
22
+ <div class="form-group">
23
+ <label for="exampleInputEmail1">Email address</label>
24
+ <input type="text" name="title" class="form-control" placeholder="제목">
25
+ </div>
26
+ <div class="form-group">
27
+ <label for="exampleInputPassword1">Password</label>
28
+ <textarea class="form-control" name="content"></textarea>
29
+ </div>
30
+ <button type="submit" class="btn btn-default">Submit</button>
31
+ </form>
32
+ </div>
@@ -0,0 +1,25 @@
1
+ class BoardController < ApplicationController
2
+ def index
3
+ @post = Post.all
4
+ end
5
+
6
+ def create
7
+ @post = Post.new(title: params[:title], content: params[:content])
8
+ @post.save
9
+ redirect_to :back
10
+ end
11
+
12
+ def new
13
+ end
14
+
15
+ def edit
16
+ end
17
+
18
+ def destroy
19
+ end
20
+ def comment_create
21
+ @comment = Comment.new(post_id: params[:post_id], content: params[:content])
22
+ @comment.save
23
+ redirect_to :back
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ rails g model post title:string content:text
2
+ rails g model comment content:string post_id:integer
3
+ rails g controller board index create new edit destroy
@@ -0,0 +1,3 @@
1
+ class Comment < ActiveRecord::Base
2
+ belongs_to :post
3
+ end
@@ -0,0 +1,10 @@
1
+ class CreateComments < ActiveRecord::Migration
2
+ def change
3
+ create_table :comments do |t|
4
+ t.string :content
5
+ t.integer :post_id
6
+
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ class CreatePosts < ActiveRecord::Migration
2
+ def change
3
+ create_table :posts do |t|
4
+ t.string :title
5
+ t.text :content
6
+
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ class Post < ActiveRecord::Base
2
+ has_many :comments
3
+ end
@@ -0,0 +1,9 @@
1
+ Rails.application.routes.draw do
2
+ root 'board#index'
3
+ get 'board/index'
4
+ post 'board/create'
5
+ get 'board/new'
6
+ get 'board/edit'
7
+ get 'board/destroy'
8
+ post 'board/:post_id/comment_create' => 'board#comment_create'
9
+ end
@@ -0,0 +1 @@
1
+ board.index.html.erb
@@ -0,0 +1,3 @@
1
+ rails g controller home index
2
+ rails g model post title:string content:text
3
+ rails g model reply content:text post_id:integer
@@ -0,0 +1,10 @@
1
+ class CreatePosts < ActiveRecord::Migration
2
+ def change
3
+ create_table :posts do |t|
4
+ t.string :title
5
+ t.text :content
6
+
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ class CreateReplies < ActiveRecord::Migration
2
+ def change
3
+ create_table :replies do |t|
4
+ t.text :content
5
+ t.integer :post_id
6
+
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,30 @@
1
+ <h1>hi</h1>
2
+ <div class="container">
3
+ <form action="/write" method="POST">
4
+ <div class="form-group">
5
+ <label for="exampleInputEmail1">제목</label>
6
+ <input type="text" name="title" class="form-control" id="exampleInputEmail1" placeholder="제목">
7
+ </div>
8
+ <label for="exampleInputEmail1">내용</label>
9
+ <textarea name="content" class="form-control" rows="5" id="commit"></textarea>
10
+ <button type="submit" class="btn btn-default" style="margin-top:20px">전송</button>
11
+ </form>
12
+
13
+ <% @posts.each do |p| %>
14
+ <div class="well">
15
+ <span style="font-weight:bold;"><%= p.title %></span><br>
16
+ <%= p.content %> <br><hr>
17
+
18
+ <% p.replies.each do |r| %>
19
+ <%= r.content %><br>
20
+ <% end %>
21
+
22
+ <form style="margin-top:40px;" action="/home/reply_write" method="POST">
23
+ <input type="hidden" value="<%= p.id%>" name="id_of_post">
24
+ <label for="exampleInputEmail1">내용</label>
25
+ <textarea name="content" class="form-control" rows="5" id="commit"></textarea>
26
+ <button type="submit" class="btn btn-default" style="margin-top:20px">전송</button>
27
+ </form>
28
+ </div>
29
+ <% end %>
30
+ </div>
@@ -0,0 +1,22 @@
1
+ class HomeController < ApplicationController
2
+ def index
3
+ @posts = Post.all
4
+ end
5
+ def write
6
+ post = Post.new
7
+ post.title = params[:title]
8
+ post.content = params[:content]
9
+ if post.save
10
+ redirect_to '/home/index'
11
+ else
12
+ render :text => post.errors.messages
13
+ end
14
+ end
15
+ def reply_write
16
+ reply = Reply.new
17
+ reply.content = params[:content]
18
+ reply.post_id = params[:id_of_post]
19
+ reply.save
20
+ redirect_to '/home/index'
21
+ end
22
+ end
@@ -0,0 +1,4 @@
1
+ class Post < ActiveRecord::Base
2
+ has_many :replies
3
+ validates :title, presence: {message: "제목을 입력해주세요."}
4
+ end
@@ -0,0 +1,2 @@
1
+ 코드가 추가되었습니다. rake db:migrate를 실행해주세요.
2
+ 시드가 있습니다. rake db:seed를 실행해주세요.
@@ -0,0 +1,3 @@
1
+ class Reply < ActiveRecord::Base
2
+ belongs_to :post
3
+ end
@@ -0,0 +1,5 @@
1
+ Rails.application.routes.draw do
2
+ get 'home/index'
3
+ post 'write' => "home#write"
4
+ post '/home/reply_write' => "home#reply_write"
5
+ end
@@ -0,0 +1,18 @@
1
+ Post.create(title: '안녕하세요', content: '첫 글 입니다.')
2
+ Post.create(:title => '두번째 글', :content => '두번째 글 입니다.')
3
+ new_post = Post.new
4
+ new_post.title = "셋째 글~!"
5
+ new_post.content = "이래도 동작함?"
6
+ new_post.save
7
+
8
+ Reply.create(:content => '댓글이당!', :post_id => 1)
9
+
10
+ reply = Reply.new
11
+ reply.content = '두번째 댓글'
12
+ reply.post_id = '1'
13
+ reply.save
14
+
15
+ reply = Reply.new
16
+ reply.content = '세번째 댓글'
17
+ reply.post = new_post
18
+ reply.save
@@ -0,0 +1 @@
1
+ home.index.html.erb
@@ -0,0 +1,3 @@
1
+ rails g controller home index
2
+ rails g model post title:string content:text
3
+ rails g model reply content:text post_id:integer
@@ -0,0 +1,10 @@
1
+ class CreatePosts < ActiveRecord::Migration
2
+ def change
3
+ create_table :posts do |t|
4
+ t.string :title
5
+ t.text :content
6
+
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ class CreateReplies < ActiveRecord::Migration
2
+ def change
3
+ create_table :replies do |t|
4
+ t.text :content
5
+ t.integer :post_id
6
+
7
+ t.timestamps null: false
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,51 @@
1
+ <h1>hi</h1>
2
+ <div class="container">
3
+ <form action="/write" method="POST">
4
+ <div class="form-group">
5
+ <label for="exampleInputEmail1">제목</label>
6
+ <input type="text" name="title" class="form-control" id="exampleInputEmail1" placeholder="제목">
7
+ </div>
8
+ <label for="exampleInputEmail1">내용</label>
9
+ <textarea name="content" class="form-control" rows="5" id="commit"></textarea>
10
+ <button type="submit" class="btn btn-default" style="margin-top:20px">전송</button>
11
+ </form>
12
+
13
+ <% @posts.each do |p| %>
14
+ <div class="well">
15
+ <span style="font-weight:bold;"><%= p.title %></span><br>
16
+ <%= p.content %> <br><hr>
17
+ <div id ="reply_<%=p.id%>">
18
+ <% p.replies.each do |r| %>
19
+ <%= r.content %><br>
20
+ <% end %>
21
+ </div>
22
+ <!--<input type="hidden" value="<#%= p.id%>" name="id_of_post">-->
23
+ <label for="exampleInputEmail1">내용</label>
24
+ <textarea name="content" class="form-control" rows="5" id="content_<%=p.id%>"></textarea>
25
+ <button value="<%= p.id %>"type="submit" class="btn btn-default reply_submit" style="margin-top:20px ">전송</button>
26
+ </div>
27
+ <% end %>
28
+ </div>
29
+
30
+ <script>
31
+ $(function(){
32
+ $(".reply_submit").click(function(){
33
+ post_id=this.value;
34
+ post_content = $("#content_"+post_id).val();
35
+
36
+ $.ajax({
37
+ method: "POST",
38
+ url: "/home/reply_write",
39
+ data: { content: post_content, id_of_post:post_id },
40
+ success: function(){
41
+ alert("리플이 작성되었습니다.");
42
+ $("#reply_"+post_id).append("<p>"+post_content+"</p>")
43
+ $("#content_"+post_id).val('');
44
+ },
45
+ error: function(){
46
+ alert("리플이 작성되지 않았습니다.");
47
+ }
48
+ })
49
+ });
50
+ });
51
+ </script>
@@ -0,0 +1,22 @@
1
+ class HomeController < ApplicationController
2
+ def index
3
+ @posts = Post.all
4
+ end
5
+ def write
6
+ post = Post.new
7
+ post.title = params[:title]
8
+ post.content = params[:content]
9
+ if post.save
10
+ redirect_to '/home/index'
11
+ else
12
+ render :text => post.errors.messages
13
+ end
14
+ end
15
+ def reply_write
16
+ reply = Reply.new
17
+ reply.content = params[:content]
18
+ reply.post_id = params[:id_of_post]
19
+ reply.save
20
+ redirect_to '/home/index'
21
+ end
22
+ end
@@ -0,0 +1,4 @@
1
+ class Post < ActiveRecord::Base
2
+ has_many :replies
3
+ validates :title, presence: {message: "제목을 입력해주세요."}
4
+ end
@@ -0,0 +1,2 @@
1
+ 코드가 추가되었습니다. rake db:migrate를 실행해주세요.
2
+ 시드가 있습니다. rake db:seed를 실행해주세요.
@@ -0,0 +1,3 @@
1
+ class Reply < ActiveRecord::Base
2
+ belongs_to :post
3
+ end
@@ -0,0 +1,5 @@
1
+ Rails.application.routes.draw do
2
+ get 'home/index'
3
+ post 'write' => "home#write"
4
+ post '/home/reply_write' => "home#reply_write"
5
+ end
@@ -0,0 +1,18 @@
1
+ Post.create(title: '안녕하세요', content: '첫 글 입니다.')
2
+ Post.create(:title => '두번째 글', :content => '두번째 글 입니다.')
3
+ new_post = Post.new
4
+ new_post.title = "셋째 글~!"
5
+ new_post.content = "이래도 동작함?"
6
+ new_post.save
7
+
8
+ Reply.create(:content => '댓글이당!', :post_id => 1)
9
+
10
+ reply = Reply.new
11
+ reply.content = '두번째 댓글'
12
+ reply.post_id = '1'
13
+ reply.save
14
+
15
+ reply = Reply.new
16
+ reply.content = '세번째 댓글'
17
+ reply.post = new_post
18
+ reply.save
@@ -0,0 +1 @@
1
+ home.index.html.erb
@@ -0,0 +1 @@
1
+ rails g controller home index
@@ -0,0 +1,12 @@
1
+ <h1>Home#index</h1>
2
+ <p>Find me in app/views/home/index.html.erb</p>
3
+ <form action="/home/upload" method ="post" enctype="multipart/form-data">
4
+ <input type="file" name="pic" accept="/image/*">
5
+ <input type="submit">
6
+ </form>
7
+
8
+ <% if flash[:notice] %>
9
+ <%= flash[:notice] %>
10
+ <% end %>
11
+
12
+ <%= yield %>
@@ -0,0 +1,13 @@
1
+ class HomeController < ApplicationController
2
+ def index
3
+ end
4
+ def upload
5
+ file = params[:pic]
6
+
7
+ uploader= LightUploader.new
8
+ uploader.store!(file)
9
+
10
+ flash[:notice]="전송되었습니다"
11
+ redirect_to "/home/index"
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ CarrierWave.configure do |config|
2
+ config.fog_credentials = {
3
+ provider: 'AWS',
4
+ aws_access_key_id: '자신의 id',
5
+ aws_secret_access_key: '자신의 key',
6
+ region: 'ap-northeast-2',
7
+ endpoint: 'http://s3.ap-northeast-2.amazonaws.com'
8
+ }
9
+ config.fog_directory = '자신의 bucket 이름'
10
+ config.fog_attributes = {} # optional, defaults to {}
11
+ end
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ class LightUploader < CarrierWave::Uploader::Base
4
+ # Include RMagick or MiniMagick support:
5
+ # include CarrierWave::RMagick
6
+ include CarrierWave::MiniMagick
7
+
8
+ # Choose what kind of storage to use for this uploader:
9
+ #storage :file
10
+ storage :fog
11
+
12
+ # Override the directory where uploaded files will be stored.
13
+ # This is a sensible default for uploaders that are meant to be mounted:
14
+ def store_dir
15
+ "uploads/"
16
+ end
17
+
18
+ # Provide a default URL as a default if there hasn't been a file uploaded:
19
+ # def default_url
20
+ # # For Rails 3.1+ asset pipeline compatibility:
21
+ # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
22
+ #
23
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
24
+ # end
25
+
26
+ # Process files as they are uploaded:
27
+ # process :scale => [200, 300]
28
+ #
29
+ # def scale(width, height)
30
+ # # do something
31
+ # end
32
+
33
+ # Create different versions of your uploaded files:
34
+ version :thumb do
35
+ process :resize_to_fit => [50, 50]
36
+ end
37
+ version :middle do
38
+ process :resize_to_fit => [150, 150]
39
+ end
40
+
41
+ # Add a white list of extensions which are allowed to be uploaded.
42
+ # For images you might use something like this:
43
+ # def extension_white_list
44
+ # %w(jpg jpeg gif png)
45
+ # end
46
+
47
+ # Override the filename of the uploaded files:
48
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
49
+ def filename
50
+ [*('a'..'z')].sample(20).join+"."+ file.extension if original_filename
51
+ end
52
+
53
+ end
@@ -0,0 +1,2 @@
1
+ 코드가 추가되었습니다. rake db:migrate를 실행해주세요.
2
+ Mini magick은 직접 설치해주시기 바랍니다.
@@ -0,0 +1,4 @@
1
+ Rails.application.routes.draw do
2
+ get 'home/index'
3
+ post 'home/upload'
4
+ end
@@ -0,0 +1 @@
1
+ home.index.html.erb
@@ -0,0 +1,2 @@
1
+ rails g controller home
2
+ rails g model student
@@ -0,0 +1,16 @@
1
+ class HomeController < ApplicationController
2
+ def index
3
+ highschool = Student.multi 3, 4
4
+ one_student = Student.where(:name => "이두희").take
5
+
6
+ highschool = one_student.get_enter_year
7
+ end
8
+
9
+ def create_student
10
+ highschool = Student.multi 5, 8
11
+ end
12
+
13
+ def delete_student
14
+ highschool = Student.multi 2, 5
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ 코드가 추가되었습니다. rake db:migrate를 실행해주세요.
2
+ 시드가 있습니다. rake db:seed를 실행해주세요.
3
+ 이번 강의는 Rails ActiveRecord에 관한 내용으로 설명과 함께 살펴보시기 바랍니다.
@@ -0,0 +1,2 @@
1
+ Student.create(name: "이두희", number: "2010-33993")
2
+ Student.create(name: "강동주", number: "2009-12345")
@@ -0,0 +1,14 @@
1
+ class Student < ActiveRecord::Base
2
+ def self.multi a, b
3
+ c = a * b
4
+ return c
5
+ end
6
+
7
+ def minus a, b
8
+ a - b
9
+ end
10
+
11
+ def get_enter_year
12
+ return self.number.split("-").first
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Likelion
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: likelion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ChangHee Lee
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-27 00:00:00.000000000 Z
11
+ date: 2016-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: devise
@@ -133,6 +133,59 @@ files:
133
133
  - lib/generators/likelion/templates/160413/home_controller.rb
134
134
  - lib/generators/likelion/templates/160413/routes.rb
135
135
  - lib/generators/likelion/templates/160413/views.txt
136
+ - lib/generators/likelion/templates/160415/command.txt
137
+ - lib/generators/likelion/templates/160415/create_posts.rb
138
+ - lib/generators/likelion/templates/160415/home.index.html.erb
139
+ - lib/generators/likelion/templates/160415/home.list.html.erb
140
+ - lib/generators/likelion/templates/160415/home.update_view.html.erb
141
+ - lib/generators/likelion/templates/160415/home.write.html.erb
142
+ - lib/generators/likelion/templates/160415/home_controller.rb
143
+ - lib/generators/likelion/templates/160415/routes.rb
144
+ - lib/generators/likelion/templates/160415/views.txt
145
+ - lib/generators/likelion/templates/160425/board.index.html.erb
146
+ - lib/generators/likelion/templates/160425/board_controller.rb
147
+ - lib/generators/likelion/templates/160425/command.txt
148
+ - lib/generators/likelion/templates/160425/comment.rb
149
+ - lib/generators/likelion/templates/160425/create_comments.rb
150
+ - lib/generators/likelion/templates/160425/create_posts.rb
151
+ - lib/generators/likelion/templates/160425/post.rb
152
+ - lib/generators/likelion/templates/160425/routes.rb
153
+ - lib/generators/likelion/templates/160425/views.txt
154
+ - lib/generators/likelion/templates/160427/command.txt
155
+ - lib/generators/likelion/templates/160427/create_posts.rb
156
+ - lib/generators/likelion/templates/160427/create_replies.rb
157
+ - lib/generators/likelion/templates/160427/home.index.html.erb
158
+ - lib/generators/likelion/templates/160427/home_controller.rb
159
+ - lib/generators/likelion/templates/160427/post.rb
160
+ - lib/generators/likelion/templates/160427/readme
161
+ - lib/generators/likelion/templates/160427/reply.rb
162
+ - lib/generators/likelion/templates/160427/routes.rb
163
+ - lib/generators/likelion/templates/160427/seeds.rb
164
+ - lib/generators/likelion/templates/160427/views.txt
165
+ - lib/generators/likelion/templates/160502/command.txt
166
+ - lib/generators/likelion/templates/160502/create_posts.rb
167
+ - lib/generators/likelion/templates/160502/create_replies.rb
168
+ - lib/generators/likelion/templates/160502/home.index.html.erb
169
+ - lib/generators/likelion/templates/160502/home_controller.rb
170
+ - lib/generators/likelion/templates/160502/post.rb
171
+ - lib/generators/likelion/templates/160502/readme
172
+ - lib/generators/likelion/templates/160502/reply.rb
173
+ - lib/generators/likelion/templates/160502/routes.rb
174
+ - lib/generators/likelion/templates/160502/seeds.rb
175
+ - lib/generators/likelion/templates/160502/views.txt
176
+ - lib/generators/likelion/templates/160512/command.txt
177
+ - lib/generators/likelion/templates/160512/home.index.html.erb
178
+ - lib/generators/likelion/templates/160512/home_controller.rb
179
+ - lib/generators/likelion/templates/160512/initializer.aws.rb
180
+ - lib/generators/likelion/templates/160512/light_uploader.rb
181
+ - lib/generators/likelion/templates/160512/readme
182
+ - lib/generators/likelion/templates/160512/routes.rb
183
+ - lib/generators/likelion/templates/160512/views.txt
184
+ - lib/generators/likelion/templates/160525/command.txt
185
+ - lib/generators/likelion/templates/160525/home_controller.rb
186
+ - lib/generators/likelion/templates/160525/readme
187
+ - lib/generators/likelion/templates/160525/seeds.rb
188
+ - lib/generators/likelion/templates/160525/student.rb
136
189
  - lib/likelion.rb
137
190
  - lib/likelion/version.rb
138
191
  - likelion.gemspec