@@ -186,6 +186,7 @@ class PostsController < ApplicationController
186186 def post_params
187187 params.require(:post ).permit(:username , :body )
188188 end
189+
189190end
190191```
191192
@@ -297,42 +298,42 @@ class TwitterClone::Pages::Posts::Index < Matestack::Ui::Page
297298
298299 private
299300
300- def post_form_partial
301- div class : " mb-3 p-3 rounded shadow-sm" do
302- heading size: 4 , text: " New Post" , class : " mb-3"
303- matestack_form form_config_helper do
304- div class : " mb-3" do
305- form_input key: :username , type: :text , placeholder: " Username" , class : " form-control"
306- end
307- div class : " mb-3" do
308- form_textarea key: :body , placeholder: " What's up?" , class : " form-control"
309- end
310- div class : " mb-3" do
311- button ' submit' , type: :submit , class : " btn btn-primary" , text: " Post!"
312- end
301+ def post_form_partial
302+ div class : " mb-3 p-3 rounded shadow-sm" do
303+ heading size: 4 , text: " New Post" , class : " mb-3"
304+ matestack_form form_config_helper do
305+ div class : " mb-3" do
306+ form_input key: :username , type: :text , placeholder: " Username" , class : " form-control"
307+ end
308+ div class : " mb-3" do
309+ form_textarea key: :body , placeholder: " What's up?" , class : " form-control"
310+ end
311+ div class : " mb-3" do
312+ button ' submit' , type: :submit , class : " btn btn-primary" , text: " Post!"
313313 end
314314 end
315315 end
316+ end
316317
317- def form_config_helper
318- {
319- for: Post .new , path: posts_path, method: :post ,
320- # optional: in order to map Bootstrap's CSS classes, you can adjust the form error rendering like so:
321- errors: { wrapper: { tag: :div , class : ' invalid-feedback' }, input: { class : ' is-invalid' } }
322- }
323- end
318+ def form_config_helper
319+ {
320+ for: Post .new , path: posts_path, method: :post ,
321+ # optional: in order to map Bootstrap's CSS classes, you can adjust the form error rendering like so:
322+ errors: { wrapper: { tag: :div , class : ' invalid-feedback' }, input: { class : ' is-invalid' } }
323+ }
324+ end
324325
325- def post_list_partial
326- @posts .each do |post |
327- div class : " mb-3 p-3 rounded shadow-sm" do
328- heading size: 5 do
329- plain post.username
330- small text: post.created_at.strftime(" %d.%m.%Y %H:%M" )
331- end
332- paragraph text: post.body
326+ def post_list_partial
327+ @posts .each do |post |
328+ div class : " mb-3 p-3 rounded shadow-sm" do
329+ heading size: 5 do
330+ plain post.username
331+ small text: post.created_at.strftime(" %d.%m.%Y %H:%M" )
333332 end
333+ paragraph text: post.body
334334 end
335335 end
336+ end
336337
337338end
338339```
@@ -542,37 +543,35 @@ class TwitterClone::Pages::Posts::Index < Matestack::Ui::Page
542543
543544 private
544545
545- def post_form_partial
546- div class : " mb-3 p-3 rounded shadow-sm" do
547- heading size: 4 , text: " New Post" , class : " mb-3"
548- form form_config_helper do
549- # ...
550- end
546+ def post_form_partial
547+ div class : " mb-3 p-3 rounded shadow-sm" do
548+ heading size: 4 , text: " New Post" , class : " mb-3"
549+ form form_config_helper do
550+ # ...
551551 end
552- toggle show_on: " submitted " , hide_after: 5000 do
553- div class : " container fixed-bottom w-100 bg-success text-white p-3 rounded-top " do
554- heading size: 4 , text: " Success: {{ event.data.message }} "
555- end
552+ end
553+ toggle show_on : " submitted " , hide_after: 5000 do
554+ div class : " container fixed-bottom w-100 bg-success text-white p-3 rounded-top " do
555+ heading size: 4 , text: " Success: {{ event.data.message }} "
556556 end
557- toggle show_on: " form_failed " , hide_after: 5000 do
558- div class : " container fixed-bottom w-100 bg-danger text-white p-3 rounded-top " do
559- heading size: 4 , text: " Error: {{ event.data.message }} "
560- end
557+ end
558+ toggle show_on : " form_failed " , hide_after: 5000 do
559+ div class : " container fixed-bottom w-100 bg-danger text-white p-3 rounded-top " do
560+ heading size: 4 , text: " Error: {{ event.data.message }} "
561561 end
562562 end
563+ end
563564
564- private
565-
566- def form_config_helper
567- {
568- for: Post .new , path: posts_path, method: :post ,
569- success: { emit: " submitted" },
570- failure: { emit: " form_failed" },
571- errors: { wrapper: { tag: :div , class : ' invalid-feedback' }, input: { class : ' is-invalid' } }
572- }
573- end
565+ def form_config_helper
566+ {
567+ for: Post .new , path: posts_path, method: :post ,
568+ success: { emit: " submitted" },
569+ failure: { emit: " form_failed" },
570+ errors: { wrapper: { tag: :div , class : ' invalid-feedback' }, input: { class : ' is-invalid' } }
571+ }
572+ end
574573
575- # ...
574+ # ...
576575
577576end
578577```
@@ -967,16 +966,16 @@ class TwitterClone::Pages::Posts::Index < Matestack::Ui::Page
967966
968967 private
969968
970- # ...
969+ # ...
971970
972- def post_list_partial
973- # async rerender_on: "submitted", id: "post-list" do
974- cable prepend_on: " cable__created_post" , id: " post-list" do
975- @posts .each do |post |
976- post_component post: post
977- end
971+ def post_list_partial
972+ # async rerender_on: "submitted", id: "post-list" do
973+ cable prepend_on: " cable__created_post" , id: " post-list" do
974+ @posts .each do |post |
975+ post_component post: post
978976 end
979977 end
978+ end
980979
981980end
982981```
@@ -1040,16 +1039,16 @@ class TwitterClone::Pages::Posts::Index < Matestack::Ui::Page
10401039
10411040 private
10421041
1043- # ...
1042+ # ...
10441043
1045- def post_list_partial
1046- # cable prepend_on: "cable__created_post", id: "post-list" do
1047- cable prepend_on: " cable__created_post" , update_on: " cable__liked_post" , id: " post-list" do
1048- @posts .each do |post |
1049- post_component post: post
1050- end
1044+ def post_list_partial
1045+ # cable prepend_on: "cable__created_post", id: "post-list" do
1046+ cable prepend_on: " cable__created_post" , update_on: " cable__liked_post" , id: " post-list" do
1047+ @posts .each do |post |
1048+ post_component post: post
10511049 end
10521050 end
1051+ end
10531052
10541053end
10551054```
@@ -1162,8 +1161,6 @@ Relax, it's super simple:
11621161
11631162` app/matestack/twitter_clone/posts/index.rb `
11641163
1165- # todo: indetation of private sections
1166-
11671164``` ruby
11681165class TwitterClone ::Pages ::Posts ::Index < Matestack ::Ui ::Page
11691166
@@ -1178,22 +1175,22 @@ class TwitterClone::Pages::Posts::Index < Matestack::Ui::Page
11781175
11791176 private
11801177
1181- # ...
1178+ # ...
11821179
1183- def posts
1184- Post .all
1185- end
1180+ def posts
1181+ Post .all
1182+ end
11861183
1187- def post_list_partial
1188- async defer: true , id: " deferred-post-list" do
1189- cable prepend_on: " cable__created_post" , update_on: " cable__liked_post" , id: " post-list" do
1190- # @posts.each do |post|
1191- posts.each do |post |
1192- post_component post: post
1193- end
1184+ def post_list_partial
1185+ async defer: true , id: " deferred-post-list" do
1186+ cable prepend_on: " cable__created_post" , update_on: " cable__liked_post" , id: " post-list" do
1187+ # @posts.each do |post|
1188+ posts.each do |post |
1189+ post_component post: post
11941190 end
11951191 end
11961192 end
1193+ end
11971194
11981195end
11991196```
@@ -1280,36 +1277,36 @@ class TwitterClone::Pages::Posts::Index < Matestack::Ui::Page
12801277
12811278 private
12821279
1283- def post_form_partial
1284- div class : " mb-3 p-3 rounded shadow-sm" do
1285- heading size: 4 , text: " New Post" , class : " mb-3"
1286- form form_config_helper do
1287- # div class: "mb-3" do
1288- # form_input key: :username, type: :text, placeholder: "Username", class: "form-control"
1289- # end
1290- div class : " mb-3" do
1291- form_input key: :body , type: :text , placeholder: " What's up?" , class : " form-control"
1292- end
1293- div class : " mb-3" do
1294- form_submit do
1295- button type: :submit , class : " btn btn-primary" , text: " Post!"
1296- end
1280+ def post_form_partial
1281+ div class : " mb-3 p-3 rounded shadow-sm" do
1282+ heading size: 4 , text: " New Post" , class : " mb-3"
1283+ form form_config_helper do
1284+ # div class: "mb-3" do
1285+ # form_input key: :username, type: :text, placeholder: "Username", class: "form-control"
1286+ # end
1287+ div class : " mb-3" do
1288+ form_input key: :body , type: :text , placeholder: " What's up?" , class : " form-control"
1289+ end
1290+ div class : " mb-3" do
1291+ form_submit do
1292+ button type: :submit , class : " btn btn-primary" , text: " Post!"
12971293 end
12981294 end
12991295 end
1300- # toggle show_on: "submitted", hide_after: 5000 do
1301- # div class: "container fixed-bottom w-100 bg-success text-white p-3 rounded-top" do
1302- # heading size: 4, text: "Success: {{ event.data.message }}"
1303- # end
1304- # end
1305- # toggle show_on: "form_failed", hide_after: 5000 do
1306- # div class: "container fixed-bottom w-100 bg-danger text-white p-3 rounded-top" do
1307- # heading size: 4, text: "Error: {{ event.data.message }}"
1308- # end
1309- # end
13101296 end
1297+ # toggle show_on: "submitted", hide_after: 5000 do
1298+ # div class: "container fixed-bottom w-100 bg-success text-white p-3 rounded-top" do
1299+ # heading size: 4, text: "Success: {{ event.data.message }}"
1300+ # end
1301+ # end
1302+ # toggle show_on: "form_failed", hide_after: 5000 do
1303+ # div class: "container fixed-bottom w-100 bg-danger text-white p-3 rounded-top" do
1304+ # heading size: 4, text: "Error: {{ event.data.message }}"
1305+ # end
1306+ # end
1307+ end
13111308
1312- # ...
1309+ # ...
13131310
13141311end
13151312```
@@ -1453,10 +1450,10 @@ class ProfileController < ApplicationController
14531450
14541451 private
14551452
1456- # Only allow a list of trusted parameters through.
1457- def profile_params
1458- params.require(:profile ).permit(:username )
1459- end
1453+ # Only allow a list of trusted parameters through.
1454+ def profile_params
1455+ params.require(:profile ).permit(:username )
1456+ end
14601457
14611458end
14621459```
0 commit comments