-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path;
322 lines (320 loc) · 12.1 KB
/
;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
[33mcommit 00da767361b82599e812357e566ddb77d504a131[m
Author: Alon Lavi <[email protected]>
Date: Wed Oct 10 04:49:33 2012 -0400
Finish demo app
[1mdiff --git a/app/assets/javascripts/microposts.js.coffee b/app/assets/javascripts/microposts.js.coffee[m
[1mnew file mode 100644[m
[1mindex 0000000..7615679[m
[1m--- /dev/null[m
[1m+++ b/app/assets/javascripts/microposts.js.coffee[m
[36m@@ -0,0 +1,3 @@[m
[32m+[m[32m# Place all the behaviors and hooks related to the matching controller here.[m
[32m+[m[32m# All this logic will automatically be available in application.js.[m
[32m+[m[32m# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/[m
[1mdiff --git a/app/assets/stylesheets/microposts.css.scss b/app/assets/stylesheets/microposts.css.scss[m
[1mnew file mode 100644[m
[1mindex 0000000..c14d62c[m
[1m--- /dev/null[m
[1m+++ b/app/assets/stylesheets/microposts.css.scss[m
[36m@@ -0,0 +1,3 @@[m
[32m+[m[32m// Place all the styles related to the Microposts controller here.[m
[32m+[m[32m// They will automatically be included in application.css.[m
[32m+[m[32m// You can use Sass (SCSS) here: http://sass-lang.com/[m
[1mdiff --git a/app/controllers/microposts_controller.rb b/app/controllers/microposts_controller.rb[m
[1mnew file mode 100644[m
[1mindex 0000000..6ed1cd4[m
[1m--- /dev/null[m
[1m+++ b/app/controllers/microposts_controller.rb[m
[36m@@ -0,0 +1,83 @@[m
[32m+[m[32mclass MicropostsController < ApplicationController[m
[32m+[m[32m # GET /microposts[m
[32m+[m[32m # GET /microposts.json[m
[32m+[m[32m def index[m
[32m+[m[32m @microposts = Micropost.all[m
[32m+[m
[32m+[m[32m respond_to do |format|[m
[32m+[m[32m format.html # index.html.erb[m
[32m+[m[32m format.json { render json: @microposts }[m
[32m+[m[32m end[m
[32m+[m[32m end[m
[32m+[m
[32m+[m[32m # GET /microposts/1[m
[32m+[m[32m # GET /microposts/1.json[m
[32m+[m[32m def show[m
[32m+[m[32m @micropost = Micropost.find(params[:id])[m
[32m+[m
[32m+[m[32m respond_to do |format|[m
[32m+[m[32m format.html # show.html.erb[m
[32m+[m[32m format.json { render json: @micropost }[m
[32m+[m[32m end[m
[32m+[m[32m end[m
[32m+[m
[32m+[m[32m # GET /microposts/new[m
[32m+[m[32m # GET /microposts/new.json[m
[32m+[m[32m def new[m
[32m+[m[32m @micropost = Micropost.new[m
[32m+[m
[32m+[m[32m respond_to do |format|[m
[32m+[m[32m format.html # new.html.erb[m
[32m+[m[32m format.json { render json: @micropost }[m
[32m+[m[32m end[m
[32m+[m[32m end[m
[32m+[m
[32m+[m[32m # GET /microposts/1/edit[m
[32m+[m[32m def edit[m
[32m+[m[32m @micropost = Micropost.find(params[:id])[m
[32m+[m[32m end[m
[32m+[m
[32m+[m[32m # POST /microposts[m
[32m+[m[32m # POST /microposts.json[m
[32m+[m[32m def create[m
[32m+[m[32m @micropost = Micropost.new(params[:micropost])[m
[32m+[m
[32m+[m[32m respond_to do |format|[m
[32m+[m[32m if @micropost.save[m
[32m+[m[32m format.html { redirect_to @micropost, notice: 'Micropost was successfully created.' }[m
[32m+[m[32m format.json { render json: @micropost, status: :created, location: @micropost }[m
[32m+[m[32m else[m
[32m+[m[32m format.html { render action: "new" }[m
[32m+[m[32m format.json { render json: @micropost.errors, status: :unprocessable_entity }[m
[32m+[m[32m end[m
[32m+[m[32m end[m
[32m+[m[32m end[m
[32m+[m
[32m+[m[32m # PUT /microposts/1[m
[32m+[m[32m # PUT /microposts/1.json[m
[32m+[m[32m def update[m
[32m+[m[32m @micropost = Micropost.find(params[:id])[m
[32m+[m
[32m+[m[32m respond_to do |format|[m
[32m+[m[32m if @micropost.update_attributes(params[:micropost])[m
[32m+[m[32m format.html { redirect_to @micropost, notice: 'Micropost was successfully updated.' }[m
[32m+[m[32m format.json { head :no_content }[m
[32m+[m[32m else[m
[32m+[m[32m format.html { render action: "edit" }[m
[32m+[m[32m format.json { render json: @micropost.errors, status: :unprocessable_entity }[m
[32m+[m[32m end[m
[32m+[m[32m end[m
[32m+[m[32m end[m
[32m+[m
[32m+[m[32m # DELETE /microposts/1[m
[32m+[m[32m # DELETE /microposts/1.json[m
[32m+[m[32m def destroy[m
[32m+[m[32m @micropost = Micropost.find(params[:id])[m
[32m+[m[32m @micropost.destroy[m
[32m+[m
[32m+[m[32m respond_to do |format|[m
[32m+[m[32m format.html { redirect_to microposts_url }[m
[32m+[m[32m format.json { head :no_content }[m
[32m+[m[32m end[m
[32m+[m[32m end[m
[32m+[m[32mend[m
[1mdiff --git a/app/helpers/microposts_helper.rb b/app/helpers/microposts_helper.rb[m
[1mnew file mode 100644[m
[1mindex 0000000..f08aad2[m
[1m--- /dev/null[m
[1m+++ b/app/helpers/microposts_helper.rb[m
[36m@@ -0,0 +1,2 @@[m
[32m+[m[32mmodule MicropostsHelper[m
[32m+[m[32mend[m
[1mdiff --git a/app/models/micropost.rb b/app/models/micropost.rb[m
[1mnew file mode 100644[m
[1mindex 0000000..8d14ac8[m
[1m--- /dev/null[m
[1m+++ b/app/models/micropost.rb[m
[36m@@ -0,0 +1,7 @@[m
[32m+[m[32mclass Micropost < ActiveRecord::Base[m
[32m+[m[32m attr_accessible :content, :user_id[m
[32m+[m
[32m+[m[32m belongs_to :user[m
[32m+[m
[32m+[m[32m validates :content, :length => { :maximum => 140 }[m
[32m+[m[32mend[m
\ No newline at end of file[m
[1mdiff --git a/app/models/user.rb b/app/models/user.rb[m
[1mindex 942ec39..60fce9d 100644[m
[1m--- a/app/models/user.rb[m
[1m+++ b/app/models/user.rb[m
[36m@@ -1,3 +1,4 @@[m
class User < ActiveRecord::Base[m
attr_accessible :email, :name[m
[31m-end[m
[32m+[m[32m has_many :microposts[m
[32m+[m[32mend[m
\ No newline at end of file[m
[1mdiff --git a/app/views/microposts/_form.html.erb b/app/views/microposts/_form.html.erb[m
[1mnew file mode 100644[m
[1mindex 0000000..4260441[m
[1m--- /dev/null[m
[1m+++ b/app/views/microposts/_form.html.erb[m
[36m@@ -0,0 +1,25 @@[m
[32m+[m[32m<%= form_for(@micropost) do |f| %>[m
[32m+[m[32m <% if @micropost.errors.any? %>[m
[32m+[m[32m <div id="error_explanation">[m
[32m+[m[32m <h2><%= pluralize(@micropost.errors.count, "error") %> prohibited this micropost from being saved:</h2>[m
[32m+[m
[32m+[m[32m <ul>[m
[32m+[m[32m <% @micropost.errors.full_messages.each do |msg| %>[m
[32m+[m[32m <li><%= msg %></li>[m
[32m+[m[32m <% end %>[m
[32m+[m[32m </ul>[m
[32m+[m[32m </div>[m
[32m+[m[32m <% end %>[m
[32m+[m
[32m+[m[32m <div class="field">[m
[32m+[m[32m <%= f.label :content %><br />[m
[32m+[m[32m <%= f.text_field :content %>[m
[32m+[m[32m </div>[m
[32m+[m[32m <div class="field">[m
[32m+[m[32m <%= f.label :user_id %><br />[m
[32m+[m[32m <%= f.number_field :user_id %>[m
[32m+[m[32m </div>[m
[32m+[m[32m <div class="actions">[m
[32m+[m[32m <%= f.submit %>[m
[32m+[m[32m </div>[m
[32m+[m[32m<% end %>[m
[1mdiff --git a/app/views/microposts/edit.html.erb b/app/views/microposts/edit.html.erb[m
[1mnew file mode 100644[m
[1mindex 0000000..30f1480[m
[1m--- /dev/null[m
[1m+++ b/app/views/microposts/edit.html.erb[m
[36m@@ -0,0 +1,6 @@[m
[32m+[m[32m<h1>Editing micropost</h1>[m
[32m+[m
[32m+[m[32m<%= render 'form' %>[m
[32m+[m
[32m+[m[32m<%= link_to 'Show', @micropost %> |[m
[32m+[m[32m<%= link_to 'Back', microposts_path %>[m
[1mdiff --git a/app/views/microposts/index.html.erb b/app/views/microposts/index.html.erb[m
[1mnew file mode 100644[m
[1mindex 0000000..e73014c[m
[1m--- /dev/null[m
[1m+++ b/app/views/microposts/index.html.erb[m
[36m@@ -0,0 +1,25 @@[m
[32m+[m[32m<h1>Listing microposts</h1>[m
[32m+[m
[32m+[m[32m<table>[m
[32m+[m[32m <tr>[m
[32m+[m[32m <th>Content</th>[m
[32m+[m[32m <th>User</th>[m
[32m+[m[32m <th></th>[m
[32m+[m[32m <th></th>[m
[32m+[m[32m <th></th>[m
[32m+[m[32m </tr>[m
[32m+[m
[32m+[m[32m<% @microposts.each do |micropost| %>[m
[32m+[m[32m <tr>[m
[32m+[m[32m <td><%= micropost.content %></td>[m
[32m+[m[32m <td><%= micropost.user_id %></td>[m
[32m+[m[32m <td><%= link_to 'Show', micropost %></td>[m
[32m+[m[32m <td><%= link_to 'Edit', edit_micropost_path(micropost) %></td>[m
[32m+[m[32m <td><%= link_to 'Destroy', micropost, method: :delete, data: { confirm: 'Are you sure?' } %></td>[m
[32m+[m[32m </tr>[m
[32m+[m[32m<% end %>[m
[32m+[m[32m</table>[m
[32m+[m
[32m+[m[32m<br />[m
[32m+[m
[32m+[m[32m<%= link_to 'New Micropost', new_micropost_path %>[m
[1mdiff --git a/app/views/microposts/new.html.erb b/app/views/microposts/new.html.erb[m
[1mnew file mode 100644[m
[1mindex 0000000..b0ef41f[m
[1m--- /dev/null[m
[1m+++ b/app/views/microposts/new.html.erb[m
[36m@@ -0,0 +1,5 @@[m
[32m+[m[32m<h1>New micropost</h1>[m
[32m+[m
[32m+[m[32m<%= render 'form' %>[m
[32m+[m
[32m+[m[32m<%= link_to 'Back', microposts_path %>[m
[1mdiff --git a/app/views/microposts/show.html.erb b/app/views/microposts/show.html.erb[m
[1mnew file mode 100644[m
[1mindex 0000000..e15f8ee[m
[1m--- /dev/null[m
[1m+++ b/app/views/microposts/show.html.erb[m
[36m@@ -0,0 +1,15 @@[m
[32m+[m[32m<p id="notice"><%= notice %></p>[m
[32m+[m
[32m+[m[32m<p>[m
[32m+[m[32m <b>Content:</b>[m
[32m+[m[32m <%= @micropost.content %>[m
[32m+[m[32m</p>[m
[32m+[m
[32m+[m[32m<p>[m
[32m+[m[32m <b>User:</b>[m
[32m+[m[32m <%= @micropost.user_id %>[m
[32m+[m[32m</p>[m
[32m+[m
[32m+[m
[32m+[m[32m<%= link_to 'Edit', edit_micropost_path(@micropost) %> |[m
[32m+[m[32m<%= link_to 'Back', microposts_path %>[m
[1mdiff --git a/config/routes.rb b/config/routes.rb[m
[1mindex ea4a195..c023975 100644[m
[1m--- a/config/routes.rb[m
[1m+++ b/config/routes.rb[m
[36m@@ -1,4 +1,6 @@[m
DemoApp::Application.routes.draw do[m
[32m+[m[32m resources :microposts[m
[32m+[m
resources :users[m
[m
# The priority is based upon order of creation:[m
[1mdiff --git a/db/migrate/20121010082754_create_microposts.rb b/db/migrate/20121010082754_create_microposts.rb[m
[1mnew file mode 100644[m
[1mindex 0000000..1ea9615[m
[1m--- /dev/null[m
[1m+++ b/db/migrate/20121010082754_create_microposts.rb[m
[36m@@ -0,0 +1,10 @@[m
[32m+[m[32mclass CreateMicroposts < ActiveRecord::Migration[m
[32m+[m[32m def change[m
[32m+[m[32m create_table :microposts do |t|[m
[32m+[m[32m t.string :content[m
[32m+[m[32m t.integer :user_id[m
[32m+[m
[32m+[m[32m t.timestamps[m
[32m+[m[32m end[m
[32m+[m[32m end[m
[32m+[m[32mend[m
[1mdiff --git a/db/schema.rb b/db/schema.rb[m
[1mindex 54a200b..8602f04 100644[m
[1m--- a/db/schema.rb[m
[1m+++ b/db/schema.rb[m
[36m@@ -11,7 +11,14 @@[m
#[m
# It's strongly recommended to check this file into your version control system.[m
[m
[31m-ActiveRecord::Schema.define(:version => 20120730222138) do[m
[32m+[m[32mActiveRecord::Schema.define(:version => 20121010082754) do[m[41m[m
[32m+[m[41m[m
[32m+[m[32m create_table "microposts", :force => true do |t|[m[41m[m
[32m+[m[32m t.string "content"[m[41m[m
[32m+[m[32m t.integer "user_id"[m[41m[m
[32m+[m[32m t.datetime "created_at", :null => false[m[41m[m
[32m+[m[32m t.datetime "updated_at", :null => false[m[41m[m
[32m+[m[32m end[m[41m[m
[m
create_table "users", :force => true do |t|[m
t.string "name"[m
[1mdiff --git a/test/fixtures/microposts.yml b/test/fixtures/microposts.yml[m
[1mnew file mode 100644[m
[1mindex 0000000..0965034[m
[1m--- /dev/null[m
[1m+++ b/test/fixtures/microposts.yml[m
[36m@@ -0,0 +1,9 @@[m
[32m+[m[32m# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html[m
[32m+[m
[32m+[m[32mone:[m
[32m+[m[32m content: MyString[m
[32m+[m[32m user_id: 1[m
[32m+[m
[32m+[m[32mtwo:[m
[32m+[m[32m content: MyString[m
[32m+[m[32m user_id: 1[m