forked from railsdoc/railsdoc.github.io
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBase.html
747 lines (409 loc) Β· 21.5 KB
/
Base.html
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
---
title: AbstractController::Base
layout: default
---
<div class="main">
<div class="banner">
<span>Ruby on Rails 5.2.8</span><br />
<div class="type">Class</div>
<h1>
AbstractController::Base
<span class="parent"><
<a href="../Object.html">Object</a>
</span>
</h1>
<ul class="files">
<li><a href="../../files/actionpack/lib/abstract_controller/base_rb.html">actionpack/lib/abstract_controller/base.rb</a></li>
</ul>
</div>
<div id="bodyContent">
<div id="content">
<div class="description">
<p><a href="Base.html"><code>AbstractController::Base</code></a> is a low-level API. Nobody should be using it directly, and subclasses (like <a href="../ActionController/Base.html"><code>ActionController::Base</code></a>) are expected to provide their own <code>render</code> method, since rendering means different things depending on the context.</p>
</div>
<h2 id="methods">Methods</h2>
<ul>
<li>
<a href="#method-c-abstract-21">abstract!</a>
</li>
<li>
<a href="#method-c-action_methods">action_methods</a>
</li>
<li>
<a href="#method-i-action_methods">action_methods</a>
</li>
<li>
<a href="#method-i-action_name">action_name</a>
</li>
<li>
<a href="#method-i-available_action-3F">available_action?</a>
</li>
<li>
<a href="#method-c-clear_action_methods-21">clear_action_methods!</a>
</li>
<li>
<a href="#method-c-controller_path">controller_path</a>
</li>
<li>
<a href="#method-i-controller_path">controller_path</a>
</li>
<li>
<a href="#method-i-formats">formats</a>
</li>
<li>
<a href="#method-c-internal_methods">internal_methods</a>
</li>
<li>
<a href="#method-c-method_added">method_added</a>
</li>
<li>
<a href="#method-i-performed-3F">performed?</a>
</li>
<li>
<a href="#method-i-process">process</a>
</li>
<li>
<a href="#method-i-response_body">response_body</a>
</li>
<li>
<a href="#method-c-supports_path-3F">supports_path?</a>
</li>
</ul>
<!-- Includes -->
<h2 id="included-modules">Included Modules</h2>
<ul>
<li>
<a href="../ActiveSupport/Configurable.html">
ActiveSupport::Configurable
</a>
</li>
</ul>
<!-- Section attributes -->
<h2 id="attributes">Attributes</h2>
<table border='0' cellpadding='5'>
<tr valign='top'>
<td class='attr-rw'>
[R]
</td>
<td class='attr-name'>abstract</td>
<td class='attr-desc'></td>
</tr>
<tr valign='top'>
<td class='attr-rw'>
[R]
</td>
<td class='attr-name'>abstract?</td>
<td class='attr-desc'></td>
</tr>
</table>
<!-- Methods -->
<h2 id="class-public-methods">Class Public methods</h2>
<div class="method">
<h3 id="method-c-abstract-21">
abstract!()
</h3>
<div class="description">
<p>Define a controller as abstract. See <a href="Base.html#method-c-internal_methods"><code>internal_methods</code></a> for more details.</p>
</div>
<details class="method__source">
<summary>
<span class="label">π Source code</span>
</summary>
<pre><code class="ruby"># File actionpack/lib/abstract_controller/base.rb, line 40
def abstract!
@abstract = true
end</code></pre>
<a href="https://github.com/rails/rails/blob/26521331e5923a0c50fa50984d2f924e5f26c50b/actionpack/lib/abstract_controller/base.rb#L40" target="_blank" class="github_url">π See on GitHub</a>
</details>
</div>
<div class="method">
<h3 id="method-c-action_methods">
action_methods()
</h3>
<div class="description">
<p>A list of method names that should be considered actions. This includes all public instance methods on a controller, less any internal methods (see <a href="Base.html#method-c-internal_methods"><code>internal_methods</code></a>), adding back in any methods that are internal, but still exist on the class itself.</p>
<h4 id="method-c-action_methods-label-Returns">Returns</h4>
<ul><li>
<p><code>Set</code> - A set of all methods that should be considered actions.</p>
</li></ul>
</div>
<details class="method__source">
<summary>
<span class="label">π Source code</span>
</summary>
<pre><code class="ruby"># File actionpack/lib/abstract_controller/base.rb, line 74
def action_methods
@action_methods ||= begin
# All public instance methods of this class, including ancestors
methods = (public_instance_methods(true) -
# Except for public instance methods of Base and its ancestors
internal_methods +
# Be sure to include shadowed public instance methods of this class
public_instance_methods(false)).uniq.map(&:to_s)
methods.to_set
end
end</code></pre>
<a href="https://github.com/rails/rails/blob/26521331e5923a0c50fa50984d2f924e5f26c50b/actionpack/lib/abstract_controller/base.rb#L74" target="_blank" class="github_url">π See on GitHub</a>
</details>
</div>
<div class="method">
<h3 id="method-c-clear_action_methods-21">
clear_action_methods!()
</h3>
<div class="description">
<p><a href="Base.html#method-c-action_methods"><code>action_methods</code></a> are cached and there is sometimes a need to refresh them. <a href="Base.html#method-c-clear_action_methods-21"><code>::clear_action_methods!</code></a> allows you to do that, so next time you run <a href="Base.html#method-c-action_methods"><code>action_methods</code></a>, they will be recalculated.</p>
</div>
<details class="method__source">
<summary>
<span class="label">π Source code</span>
</summary>
<pre><code class="ruby"># File actionpack/lib/abstract_controller/base.rb, line 90
def clear_action_methods!
@action_methods = nil
end</code></pre>
<a href="https://github.com/rails/rails/blob/26521331e5923a0c50fa50984d2f924e5f26c50b/actionpack/lib/abstract_controller/base.rb#L90" target="_blank" class="github_url">π See on GitHub</a>
</details>
</div>
<div class="method">
<h3 id="method-c-controller_path">
controller_path()
</h3>
<div class="description">
<p>Returns the full controller name, underscored, without the ending Controller.</p>
<pre><code>class MyApp::MyPostsController < AbstractController::Base
end
MyApp::MyPostsController.controller_path # => "my_app/my_posts"
</code></pre>
<h4 id="method-c-controller_path-label-Returns">Returns</h4>
<ul><li>
<p><code>String</code></p>
</li></ul>
</div>
<details class="method__source">
<summary>
<span class="label">π Source code</span>
</summary>
<pre><code class="ruby"># File actionpack/lib/abstract_controller/base.rb, line 104
def controller_path
@controller_path ||= name.sub(/Controller$/, "".freeze).underscore unless anonymous?
end</code></pre>
<a href="https://github.com/rails/rails/blob/26521331e5923a0c50fa50984d2f924e5f26c50b/actionpack/lib/abstract_controller/base.rb#L104" target="_blank" class="github_url">π See on GitHub</a>
</details>
</div>
<div class="method">
<h3 id="method-c-internal_methods">
internal_methods()
</h3>
<div class="description">
<p>A list of all internal methods for a controller. This finds the first abstract superclass of a controller, and gets a list of all public instance methods on that abstract class. Public instance methods of a controller would normally be considered action methods, so methods declared on abstract classes are being removed. (<code>ActionController::Metal</code> and <a href="../ActionController/Base.html"><code>ActionController::Base</code></a> are defined as abstract)</p>
</div>
<details class="method__source">
<summary>
<span class="label">π Source code</span>
</summary>
<pre><code class="ruby"># File actionpack/lib/abstract_controller/base.rb, line 59
def internal_methods
controller = self
controller = controller.superclass until controller.abstract?
controller.public_instance_methods(true)
end</code></pre>
<a href="https://github.com/rails/rails/blob/26521331e5923a0c50fa50984d2f924e5f26c50b/actionpack/lib/abstract_controller/base.rb#L59" target="_blank" class="github_url">π See on GitHub</a>
</details>
</div>
<div class="method">
<h3 id="method-c-method_added">
method_added(name)
</h3>
<div class="description">
<p>Refresh the cached <a href="Base.html#method-c-action_methods"><code>action_methods</code></a> when a new action_method is added.</p>
</div>
<details class="method__source">
<summary>
<span class="label">π Source code</span>
</summary>
<pre><code class="ruby"># File actionpack/lib/abstract_controller/base.rb, line 109
def method_added(name)
super
clear_action_methods!
end</code></pre>
<a href="https://github.com/rails/rails/blob/26521331e5923a0c50fa50984d2f924e5f26c50b/actionpack/lib/abstract_controller/base.rb#L109" target="_blank" class="github_url">π See on GitHub</a>
</details>
</div>
<div class="method">
<h3 id="method-c-supports_path-3F">
supports_path?()
</h3>
<div class="description">
<p>Returns true if the given controller is capable of rendering a path. A subclass of <code>AbstractController::Base</code> may return false. An Email controller for example does not support paths, only full URLs.</p>
</div>
<details class="method__source">
<summary>
<span class="label">π Source code</span>
</summary>
<pre><code class="ruby"># File actionpack/lib/abstract_controller/base.rb, line 172
def self.supports_path?
true
end</code></pre>
<a href="https://github.com/rails/rails/blob/26521331e5923a0c50fa50984d2f924e5f26c50b/actionpack/lib/abstract_controller/base.rb#L172" target="_blank" class="github_url">π See on GitHub</a>
</details>
</div>
<h2 id="instance-public-methods">Instance Public methods</h2>
<div class="method">
<h3 id="method-i-action_methods">
action_methods()
</h3>
<div class="description">
<p>Delegates to the class' <a href="Base.html#method-c-action_methods"><code>::action_methods</code></a></p>
</div>
<details class="method__source">
<summary>
<span class="label">π Source code</span>
</summary>
<pre><code class="ruby"># File actionpack/lib/abstract_controller/base.rb, line 143
def action_methods
self.class.action_methods
end</code></pre>
<a href="https://github.com/rails/rails/blob/26521331e5923a0c50fa50984d2f924e5f26c50b/actionpack/lib/abstract_controller/base.rb#L143" target="_blank" class="github_url">π See on GitHub</a>
</details>
</div>
<div class="method">
<h3 id="method-i-action_name">
action_name
</h3>
<div class="description">
<p>Returns the name of the action this controller is processing.</p>
</div>
<details class="method__source">
<summary>
<span class="label">π Source code</span>
</summary>
<pre><code class="ruby"># File actionpack/lib/abstract_controller/base.rb, line 25
attr_internal :action_name
</code></pre>
<a href="https://github.com/rails/rails/blob/26521331e5923a0c50fa50984d2f924e5f26c50b/actionpack/lib/abstract_controller/base.rb#L25" target="_blank" class="github_url">π See on GitHub</a>
</details>
</div>
<div class="method">
<h3 id="method-i-available_action-3F">
available_action?(action_name)
</h3>
<div class="description">
<p>Returns true if a method for the action is available and can be dispatched, false otherwise.</p>
<p>Notice that <code>action_methods.include?("foo")</code> may return false and <code>available_action?("foo")</code> returns true because this method considers actions that are also available through other means, for example, implicit render ones.</p>
<h4 id="method-i-available_action-3F-label-Parameters">Parameters</h4>
<ul><li>
<p><code>action_name</code> - The name of an action to be tested</p>
</li></ul>
</div>
<details class="method__source">
<summary>
<span class="label">π Source code</span>
</summary>
<pre><code class="ruby"># File actionpack/lib/abstract_controller/base.rb, line 157
def available_action?(action_name)
_find_action_name(action_name)
end</code></pre>
<a href="https://github.com/rails/rails/blob/26521331e5923a0c50fa50984d2f924e5f26c50b/actionpack/lib/abstract_controller/base.rb#L157" target="_blank" class="github_url">π See on GitHub</a>
</details>
</div>
<div class="method">
<h3 id="method-i-controller_path">
controller_path()
</h3>
<div class="description">
<p>Delegates to the class' <a href="Base.html#method-c-controller_path"><code>::controller_path</code></a></p>
</div>
<details class="method__source">
<summary>
<span class="label">π Source code</span>
</summary>
<pre><code class="ruby"># File actionpack/lib/abstract_controller/base.rb, line 138
def controller_path
self.class.controller_path
end</code></pre>
<a href="https://github.com/rails/rails/blob/26521331e5923a0c50fa50984d2f924e5f26c50b/actionpack/lib/abstract_controller/base.rb#L138" target="_blank" class="github_url">π See on GitHub</a>
</details>
</div>
<div class="method">
<h3 id="method-i-formats">
formats
</h3>
<div class="description">
<p>Returns the formats that can be processed by the controller.</p>
</div>
<details class="method__source">
<summary>
<span class="label">π Source code</span>
</summary>
<pre><code class="ruby"># File actionpack/lib/abstract_controller/base.rb, line 29
attr_internal :formats
</code></pre>
<a href="https://github.com/rails/rails/blob/26521331e5923a0c50fa50984d2f924e5f26c50b/actionpack/lib/abstract_controller/base.rb#L29" target="_blank" class="github_url">π See on GitHub</a>
</details>
</div>
<div class="method">
<h3 id="method-i-performed-3F">
performed?()
</h3>
<div class="description">
<p>Tests if a response body is set. Used to determine if the <code>process_action</code> callback needs to be terminated in <code>AbstractController::Callbacks</code>.</p>
</div>
<details class="method__source">
<summary>
<span class="label">π Source code</span>
</summary>
<pre><code class="ruby"># File actionpack/lib/abstract_controller/base.rb, line 164
def performed?
response_body
end</code></pre>
<a href="https://github.com/rails/rails/blob/26521331e5923a0c50fa50984d2f924e5f26c50b/actionpack/lib/abstract_controller/base.rb#L164" target="_blank" class="github_url">π See on GitHub</a>
</details>
</div>
<div class="method">
<h3 id="method-i-process">
process(action, *args)
</h3>
<div class="description">
<p>Calls the action going through the entire action dispatch stack.</p>
<p>The actual method that is called is determined by calling method_for_action. If no method can handle the action, then an <a href="ActionNotFound.html"><code>AbstractController::ActionNotFound</code></a> error is raised.</p>
<h4 id="method-i-process-label-Returns">Returns</h4>
<ul><li>
<p><code>self</code></p>
</li></ul>
</div>
<details class="method__source">
<summary>
<span class="label">π Source code</span>
</summary>
<pre><code class="ruby"># File actionpack/lib/abstract_controller/base.rb, line 125
def process(action, *args)
@_action_name = action.to_s
unless action_name = _find_action_name(@_action_name)
raise ActionNotFound, "The action '#{action}' could not be found for #{self.class.name}"
end
@_response_body = nil
process_action(action_name, *args)
end</code></pre>
<a href="https://github.com/rails/rails/blob/26521331e5923a0c50fa50984d2f924e5f26c50b/actionpack/lib/abstract_controller/base.rb#L125" target="_blank" class="github_url">π See on GitHub</a>
</details>
</div>
<div class="method">
<h3 id="method-i-response_body">
response_body
</h3>
<div class="description">
<p>Returns the body of the HTTP response sent by the controller.</p>
</div>
<details class="method__source">
<summary>
<span class="label">π Source code</span>
</summary>
<pre><code class="ruby"># File actionpack/lib/abstract_controller/base.rb, line 21
attr_internal :response_body
</code></pre>
<a href="https://github.com/rails/rails/blob/26521331e5923a0c50fa50984d2f924e5f26c50b/actionpack/lib/abstract_controller/base.rb#L21" target="_blank" class="github_url">π See on GitHub</a>
</details>
</div>
</div>
</div>
</div>