public
Fork of drnic/ruby-on-rails-tmbundle
Description: Ruby on Rails TextMate bundle [master branch is svn trunk; patches to drnicwilliams@gmail.com]
Homepage: http://macromates.com
Clone URL: git://github.com/Infininight/ruby-on-rails-tmbundle.git
Added duplicate form_for helpers with tab completion
drnic (author)
Mon Feb 25 21:23:44 -0800 2008
commit  d019690a73e678067b8c24e073463194de8b110f
tree    3fbf86c04396c6d038a39266c53e379f254b8d40
parent  43b11db7025659ea07680da58c3bfe17a408db52
...
5
6
7
8
 
9
10
11
...
5
6
7
 
8
9
10
11
0
@@ -5,7 +5,7 @@
0
   <key>content</key>
0
   <string>&lt;%= f.check_box :${1:attribute} %&gt;</string>
0
   <key>name</key>
0
- <string>form_for check_box</string>
0
+ <string>form_for check_box (f.)</string>
0
   <key>scope</key>
0
   <string>text.html.ruby</string>
0
   <key>tabTrigger</key>
...
5
6
7
8
 
9
10
11
...
5
6
7
 
8
9
10
11
0
@@ -5,7 +5,7 @@
0
   <key>content</key>
0
   <string>&lt;%= f.file_field :${1:attribute} %&gt;</string>
0
   <key>name</key>
0
- <string>form_for file_field</string>
0
+ <string>form_for file_field (f.)</string>
0
   <key>scope</key>
0
   <string>text.html.ruby</string>
0
   <key>tabTrigger</key>
...
5
6
7
8
 
9
10
11
...
5
6
7
 
8
9
10
11
0
@@ -5,7 +5,7 @@
0
   <key>content</key>
0
   <string>&lt;%= f.hidden_field :${1:attribute} %&gt;</string>
0
   <key>name</key>
0
- <string>form_for hidden_field</string>
0
+ <string>form_for hidden_field (f.)</string>
0
   <key>scope</key>
0
   <string>text.html.ruby</string>
0
   <key>tabTrigger</key>
...
5
6
7
8
 
9
10
11
...
5
6
7
 
8
9
10
11
0
@@ -5,7 +5,7 @@
0
   <key>content</key>
0
   <string>&lt;%= f.label :${1:attribute}${2:, "${3:${1/[[:alpha:]]+|(_)/(?1: :\u$0)/g}}"} %&gt;</string>
0
   <key>name</key>
0
- <string>form_for label</string>
0
+ <string>form_for label (f.)</string>
0
   <key>scope</key>
0
   <string>text.html.ruby</string>
0
   <key>tabTrigger</key>
...
5
6
7
8
 
9
10
11
...
5
6
7
 
8
9
10
11
0
@@ -5,7 +5,7 @@
0
   <key>content</key>
0
   <string>&lt;%= f.password_field :${1:attribute} %&gt;</string>
0
   <key>name</key>
0
- <string>form_for password_field</string>
0
+ <string>form_for password_field (f.)</string>
0
   <key>scope</key>
0
   <string>text.html.ruby</string>
0
   <key>tabTrigger</key>
...
5
6
7
8
 
9
10
11
...
5
6
7
 
8
9
10
11
0
@@ -5,7 +5,7 @@
0
   <key>content</key>
0
   <string>&lt;%= f.radio_box :${1:attribute}, :${2:tag_value} %&gt;</string>
0
   <key>name</key>
0
- <string>form_for radio_box</string>
0
+ <string>form_for radio_box (f.)</string>
0
   <key>scope</key>
0
   <string>text.html.ruby</string>
0
   <key>tabTrigger</key>
...
5
6
7
8
 
9
10
11
...
5
6
7
 
8
9
10
11
0
@@ -5,7 +5,7 @@
0
   <key>content</key>
0
   <string>&lt;%= f.submit "${1:Submit}"${2:, :disable_with =&gt; '$1ing...'} %&gt;</string>
0
   <key>name</key>
0
- <string>form_for submit</string>
0
+ <string>form_for submit (f.)</string>
0
   <key>scope</key>
0
   <string>text.html.ruby</string>
0
   <key>tabTrigger</key>
...
5
6
7
8
 
9
10
11
...
5
6
7
 
8
9
10
11
0
@@ -5,7 +5,7 @@
0
   <key>content</key>
0
   <string>&lt;%= f.text_area :${1:attribute} %&gt;</string>
0
   <key>name</key>
0
- <string>form_for text_area</string>
0
+ <string>form_for text_area (f.)</string>
0
   <key>scope</key>
0
   <string>text.html.ruby</string>
0
   <key>tabTrigger</key>
...
5
6
7
8
 
9
10
11
...
5
6
7
 
8
9
10
11
0
@@ -5,7 +5,7 @@
0
   <key>content</key>
0
   <string>&lt;%= f.text_field :${1:attribute} %&gt;</string>
0
   <key>name</key>
0
- <string>form_for text_field</string>
0
+ <string>form_for text_field (f.)</string>
0
   <key>scope</key>
0
   <string>text.html.ruby</string>
0
   <key>tabTrigger</key>
...
219
220
221
222
 
223
224
225
...
219
220
221
 
222
223
224
225
0
@@ -219,7 +219,7 @@
0
       <key>begin</key>
0
       <string>(^\s*)ActionController::Routing::Routes</string>
0
       <key>comment</key>
0
- <string>Uses ActionController::Routing::Routes to determine its a routes file; includes 'source.ruby' to avoid infinite recursion</string>
0
+ <string>Uses ActionController::Routing::Routes to determine it is a routes file; includes 'source.ruby' to avoid infinite recursion</string>
0
       <key>end</key>
0
       <string>^\1(?=end)\b</string>
0
       <key>name</key>
...
112
113
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
116
117
...
414
415
416
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
417
418
419
...
445
446
447
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
448
449
450
...
453
454
455
456
457
458
459
460
461
462
463
464
 
 
465
466
467
468
469
470
471
472
473
474
475
476
 
477
478
479
...
567
568
569
 
570
 
571
 
572
 
573
 
574
 
575
 
576
 
577
 
578
579
580
...
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
...
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
...
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
...
505
506
507
 
 
 
 
 
 
 
 
 
508
509
510
511
 
 
 
 
 
 
 
 
 
 
512
513
514
515
...
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
0
@@ -112,6 +112,24 @@
0
         <key>name</key>
0
         <string>RJS</string>
0
       </dict>
0
+ <key>245AD020-669A-46E1-8123-4B9CFDF8075A</key>
0
+ <dict>
0
+ <key>items</key>
0
+ <array>
0
+ <string>326B57A7-B4A9-447B-A3D2-0EA74158E1E1</string>
0
+ <string>6BA737F0-63D1-4D82-9381-4331E18B12C5</string>
0
+ <string>750DEEF9-18A0-40FC-8E54-574CE5EE5565</string>
0
+ <string>866AAD87-E458-4F2D-9E7C-3CE73EFC047B</string>
0
+ <string>9E2B42FE-7BC8-11D9-906A-000D932CD5BA</string>
0
+ <string>B4F952F4-7BC8-11D9-906A-000D932CD5BA</string>
0
+ <string>74590E16-7BCB-11D9-906A-000D932CD5BA</string>
0
+ <string>C11C0BF5-7BC8-11D9-906A-000D932CD5BA</string>
0
+ <string>D21BE958-7BC8-11D9-906A-000D932CD5BA</string>
0
+ <string>E5E08AA0-4EDD-4583-BF07-5D6C49E98410</string>
0
+ </array>
0
+ <key>name</key>
0
+ <string>link_to</string>
0
+ </dict>
0
       <key>4D3A01D4-ACA8-49AF-B1DD-428B823964C3</key>
0
       <dict>
0
         <key>items</key>
0
@@ -414,6 +432,23 @@
0
         <key>name</key>
0
         <string>Associations</string>
0
       </dict>
0
+ <key>BA9F12E8-9151-4975-8E8A-9644290E6038</key>
0
+ <dict>
0
+ <key>items</key>
0
+ <array>
0
+ <string>402C251E-595B-4A58-8EB9-41989040F280</string>
0
+ <string>CC1BCD1C-2479-4335-B511-17B880316A75</string>
0
+ <string>06498926-F84D-466C-8736-B8A0AC586A94</string>
0
+ <string>F579F9E7-E072-4BCC-BFF9-C8C5BAE7FFA5</string>
0
+ <string>A95358D2-C68A-4894-8C36-062C9F45848A</string>
0
+ <string>42289456-C8D1-498C-AE30-5206544B349F</string>
0
+ <string>5DBA8F72-DD6C-4CBF-83FD-76301E159BA9</string>
0
+ <string>79BC2303-3D9D-4E21-AF85-73B388B7B56D</string>
0
+ <string>C315EC5D-A7F3-49CB-9795-21B78BB42FF4</string>
0
+ </array>
0
+ <key>name</key>
0
+ <string>form_for f. drop-down list</string>
0
+ </dict>
0
       <key>D4D18AD6-11DA-47F2-AAD8-F2F350EE2BB9</key>
0
       <dict>
0
         <key>items</key>
0
@@ -445,6 +480,23 @@
0
         <key>name</key>
0
         <string>Unit Tests</string>
0
       </dict>
0
+ <key>E3C11C94-8472-45CC-9258-1E5EEC7657A8</key>
0
+ <dict>
0
+ <key>items</key>
0
+ <array>
0
+ <string>B31822D9-2048-4D16-B2AF-00E0B4E5C368</string>
0
+ <string>F46EE8EE-239C-46D7-980B-3F861B7D9111</string>
0
+ <string>4C898FA8-D09C-4B28-BE42-14BB4EA4E2B1</string>
0
+ <string>F0DB6886-4FFE-45BA-907F-44326AD8142D</string>
0
+ <string>D4282CE1-4171-4B13-9220-3F2718BC2505</string>
0
+ <string>3379FB35-C664-4255-96C6-6E4B91F12759</string>
0
+ <string>99FEFD9B-5A07-46E3-950D-5C474E42B695</string>
0
+ <string>C8BA285D-E12E-4AB8-A941-514C963E8226</string>
0
+ <string>3000E569-4E19-4566-B08E-A3FFFAAC9075</string>
0
+ </array>
0
+ <key>name</key>
0
+ <string>form_for helpers</string>
0
+ </dict>
0
       <key>EE4BA904-F727-4C6B-A2CB-602E30537E38</key>
0
       <dict>
0
         <key>items</key>
0
@@ -453,27 +505,11 @@
0
           <string>------------------------------------</string>
0
           <string>7D99041D-C3B7-4940-AE64-6B1758CDB47C</string>
0
           <string>15BDD7B6-5C15-4684-93C7-A05E3D2221AC</string>
0
- <string>402C251E-595B-4A58-8EB9-41989040F280</string>
0
- <string>CC1BCD1C-2479-4335-B511-17B880316A75</string>
0
- <string>06498926-F84D-466C-8736-B8A0AC586A94</string>
0
- <string>F579F9E7-E072-4BCC-BFF9-C8C5BAE7FFA5</string>
0
- <string>A95358D2-C68A-4894-8C36-062C9F45848A</string>
0
- <string>42289456-C8D1-498C-AE30-5206544B349F</string>
0
- <string>5DBA8F72-DD6C-4CBF-83FD-76301E159BA9</string>
0
- <string>79BC2303-3D9D-4E21-AF85-73B388B7B56D</string>
0
- <string>C315EC5D-A7F3-49CB-9795-21B78BB42FF4</string>
0
+ <string>BA9F12E8-9151-4975-8E8A-9644290E6038</string>
0
+ <string>E3C11C94-8472-45CC-9258-1E5EEC7657A8</string>
0
           <string>------------------------------------</string>
0
           <string>F0F6DACA-6A0B-11D9-BDC2-000D932CD5BA</string>
0
- <string>326B57A7-B4A9-447B-A3D2-0EA74158E1E1</string>
0
- <string>6BA737F0-63D1-4D82-9381-4331E18B12C5</string>
0
- <string>750DEEF9-18A0-40FC-8E54-574CE5EE5565</string>
0
- <string>866AAD87-E458-4F2D-9E7C-3CE73EFC047B</string>
0
- <string>9E2B42FE-7BC8-11D9-906A-000D932CD5BA</string>
0
- <string>B4F952F4-7BC8-11D9-906A-000D932CD5BA</string>
0
- <string>74590E16-7BCB-11D9-906A-000D932CD5BA</string>
0
- <string>C11C0BF5-7BC8-11D9-906A-000D932CD5BA</string>
0
- <string>D21BE958-7BC8-11D9-906A-000D932CD5BA</string>
0
- <string>E5E08AA0-4EDD-4583-BF07-5D6C49E98410</string>
0
+ <string>245AD020-669A-46E1-8123-4B9CFDF8075A</string>
0
           <string>AC385ABF-96CD-4FCB-80AD-BF37D6EE79D2</string>
0
           <string>------------------------------------</string>
0
           <string>EC605540-C431-4FD0-AD91-D913118DACA7</string>
0
@@ -567,14 +603,23 @@
0
     <string>7D99041D-C3B7-4940-AE64-6B1758CDB47C</string>
0
     <string>15BDD7B6-5C15-4684-93C7-A05E3D2221AC</string>
0
     <string>402C251E-595B-4A58-8EB9-41989040F280</string>
0
+ <string>B31822D9-2048-4D16-B2AF-00E0B4E5C368</string>
0
     <string>CC1BCD1C-2479-4335-B511-17B880316A75</string>
0
+ <string>F46EE8EE-239C-46D7-980B-3F861B7D9111</string>
0
     <string>06498926-F84D-466C-8736-B8A0AC586A94</string>
0
+ <string>4C898FA8-D09C-4B28-BE42-14BB4EA4E2B1</string>
0
     <string>F579F9E7-E072-4BCC-BFF9-C8C5BAE7FFA5</string>
0
+ <string>F0DB6886-4FFE-45BA-907F-44326AD8142D</string>
0
     <string>A95358D2-C68A-4894-8C36-062C9F45848A</string>
0
+ <string>D4282CE1-4171-4B13-9220-3F2718BC2505</string>
0
     <string>42289456-C8D1-498C-AE30-5206544B349F</string>
0
+ <string>3379FB35-C664-4255-96C6-6E4B91F12759</string>
0
     <string>5DBA8F72-DD6C-4CBF-83FD-76301E159BA9</string>
0
+ <string>99FEFD9B-5A07-46E3-950D-5C474E42B695</string>
0
     <string>79BC2303-3D9D-4E21-AF85-73B388B7B56D</string>
0
+ <string>C8BA285D-E12E-4AB8-A941-514C963E8226</string>
0
     <string>C315EC5D-A7F3-49CB-9795-21B78BB42FF4</string>
0
+ <string>3000E569-4E19-4566-B08E-A3FFFAAC9075</string>
0
     <string>F0F6DACA-6A0B-11D9-BDC2-000D932CD5BA</string>
0
     <string>326B57A7-B4A9-447B-A3D2-0EA74158E1E1</string>
0
     <string>6BA737F0-63D1-4D82-9381-4331E18B12C5</string>
...
187
188
189
190
 
191
192
193
...
199
200
201
202
 
203
204
 
205
206
207
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
209
 
 
 
 
 
 
 
 
 
 
 
 
 
210
211
212
...
187
188
189
 
190
191
192
193
...
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
0
@@ -187,7 +187,7 @@ For some of the common, more complex controller actions there are also snippets.
0
 
0
 What I want the 'create' action to do is redirect back to the main blog controller for a page. Originally, I could use 'recai' for <code>redirect_to :controller => "blog", :action => "show", :id => @post</code> but its uncool to use anonymous paths.
0
 
0
-So instead let's just enter a named route that sounds nice, replace <code>@post</code> with <code>public_post_path(@post)</code>.
0
+So instead let's just enter a named route that sounds nice, replace <code>@post</code> with <code>blog_post_path(@post)</code>.
0
 
0
 [Change to the 'routes.rb' file.] So finally let's setup our routes. I'm going to delete all the default comments and default routes, and reconstruct it with named routes.
0
 
0
@@ -199,13 +199,48 @@ So we'll use 'map' to create named routes. Leave the name as 'connect' for anony
0
 
0
 <pre>map.public_page 'blog/show/:id', :controller => "blog", :action => "show"</pre>
0
 
0
-We could place this route within a with_options block, using 'mapwo'.
0
+We could place this route within a with_options block, using 'mapwo'. Then add <code>map.root</code> within it.
0
 
0
-For our posts controller, we'll use the resources snippets. We use 'maprs' and change 'resource' to 'post' and then we can tab into the block. Say we wanted comments to be a nested resource of posts, then we'd use 'maprs' again, and change 'map' to 'post' and remove the block. [then delete the comment resource + post's block].
0
+For our posts controller, we'll use the resources snippets. We use 'maprs' and change 'resource' to 'posts' and then we can tab into the block. Say we wanted comments to be a nested resource of posts, then we'd use 'maprs' again, and change 'map' to 'post' and remove the block. [then delete the comment resource + post's block].
0
 
0
 There is also a shortcut for the respond_to block - 'rest', which gives a default html response. To add additional response formats, tab on 'wants'. [remove these examples from new method]
0
 
0
+Now let's have a final look at functional tests for our create actions, which will require a POST request. [try to change to functional test] We don't have a posts_controller_test.rb, so it creates a blank file for us.
0
+
0
+To create a functional test class, use 'cla' again and select 'Create functional test class', and type 'Posts' for the class name prefix. Save the file, close the window and reopen within the project, otherwise some commands might not work if the file is initially not saved.
0
+
0
+Remember that test methods are created with 'deft', and the GET + POST methods are created with deftg and deftp. Let's test our create action with 'deftp'.
0
+
0
+Enter 'post', but remove the two optional sections as we're creating a new object, not updating an existing object. Within the <code>:post => { }</code>, type : and tab to create the hash key values.
0
+
0
+Fetch the resulting object with <code>asg</code> + 'post'.
0
+
0
+Add a redirection assertion with <code>artp</code>.
0
+
0
+<pre syntax="ruby">def test_should_post_create
0
+ post :create, :post => { :title => "hi there", :body => "oh yeah" }
0
+ assert_response :redirect
0
+ assert(post = assigns(:post), "Cannot find @post")
0
+
0
+ assert_redirected_to blog_post_path(post)
0
+end</pre>
0
+
0
+If you just want to run the tests in the current file, or in fact run any Ruby file, use Cmd+R. As we can see, this test passes.
0
+
0
 h2. Views
0
 
0
+[back to posts_controller.rb]
0
+
0
+In the posts controller, we have a new action but we haven't created a template yet. As before, we can use the Navigation cmd to change from the controller to a view. In this case, the view is based on the current method. So we place the cursor in the new method, and it will ask us to create a new.html.erb file. Here is your opportunity to rename the template with alternate format or template extensions, say .xml.builder. But we'll use .html.erb for now.
0
+
0
+h3. Diagram: form_for - ff, form_for with error output - ffe
0
+
0
+We'll use 'ffe' and enter 'post'. In Rails 2.0, the form_for helper is very powerful and knows from the object it is passed whether it is creating or updating an object.
0
+
0
+h3. Diagram: f. - list of available helpers; or use first initial of helpers' names (tf - text_field)
0
+
0
+Inside the form_for block we have two ways to access the common helpers.
0
+
0
+
0
 
0
 h2. Extending
0
\ No newline at end of file

Comments

    No one has commented yet.