hyperactiveform 0.2.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/CHANGELOG.md +7 -0
- data/README.md +10 -0
- data/docs/FormGenerator.html +193 -0
- data/docs/HyperActiveForm/Base.html +125 -41
- data/docs/HyperActiveForm/CancelFormSubmit.html +1 -1
- data/docs/HyperActiveForm/FormDidNotSubmitError.html +1 -1
- data/docs/HyperActiveForm/Generators/InstallGenerator.html +6 -6
- data/docs/HyperActiveForm/Generators.html +2 -2
- data/docs/HyperActiveForm.html +3 -3
- data/docs/Rspec/Generators/FormGenerator.html +193 -0
- data/docs/Rspec/Generators.html +115 -0
- data/docs/Rspec.html +115 -0
- data/docs/TestUnit/Generators/FormGenerator.html +193 -0
- data/docs/TestUnit/Generators.html +115 -0
- data/docs/TestUnit.html +115 -0
- data/docs/_index.html +63 -1
- data/docs/class_list.html +1 -1
- data/docs/file.README.html +40 -2
- data/docs/index.html +40 -2
- data/docs/method_list.html +32 -0
- data/docs/top-level-namespace.html +4 -2
- data/lib/generators/form/form_generator.rb +9 -0
- data/lib/generators/form/templates/form.rb +2 -0
- data/lib/{hyper_active_form/generators.rb → generators/hyper_active_form/install/install_generator.rb} +0 -2
- data/lib/generators/rspec/form_generator.rb +11 -0
- data/lib/generators/rspec/templates/form_spec.rb +5 -0
- data/lib/generators/test_unit/form_generator.rb +11 -0
- data/lib/generators/test_unit/templates/form_test.rb +7 -0
- data/lib/hyper_active_form/base.rb +5 -0
- data/lib/hyper_active_form/version.rb +1 -1
- data/lib/hyper_active_form.rb +0 -1
- metadata +17 -3
@@ -0,0 +1,115 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
Module: TestUnit::Generators
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.37
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="../css/style.css" type="text/css" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="../css/common.css" type="text/css" />
|
16
|
+
|
17
|
+
<script type="text/javascript">
|
18
|
+
pathId = "TestUnit::Generators";
|
19
|
+
relpath = '../';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="../class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="../_index.html">Index (G)</a> »
|
40
|
+
<span class='title'><span class='object_link'><a href="../TestUnit.html" title="TestUnit (module)">TestUnit</a></span></span>
|
41
|
+
»
|
42
|
+
<span class="title">Generators</span>
|
43
|
+
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div id="search">
|
47
|
+
|
48
|
+
<a class="full_list_link" id="class_list_link"
|
49
|
+
href="../class_list.html">
|
50
|
+
|
51
|
+
<svg width="24" height="24">
|
52
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
+
</svg>
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<div id="content"><h1>Module: TestUnit::Generators
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<dl>
|
80
|
+
<dt>Defined in:</dt>
|
81
|
+
<dd>lib/generators/test_unit/form_generator.rb</dd>
|
82
|
+
</dl>
|
83
|
+
|
84
|
+
</div>
|
85
|
+
|
86
|
+
<h2>Defined Under Namespace</h2>
|
87
|
+
<p class="children">
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="Generators/FormGenerator.html" title="TestUnit::Generators::FormGenerator (class)">FormGenerator</a></span>
|
93
|
+
|
94
|
+
|
95
|
+
</p>
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
</div>
|
106
|
+
|
107
|
+
<div id="footer">
|
108
|
+
Generated on Mon Jan 13 17:26:04 2025 by
|
109
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
110
|
+
0.9.37 (ruby-3.3.1).
|
111
|
+
</div>
|
112
|
+
|
113
|
+
</div>
|
114
|
+
</body>
|
115
|
+
</html>
|
data/docs/TestUnit.html
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
Module: TestUnit
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.37
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
16
|
+
|
17
|
+
<script type="text/javascript">
|
18
|
+
pathId = "TestUnit";
|
19
|
+
relpath = '';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="_index.html">Index (T)</a> »
|
40
|
+
|
41
|
+
|
42
|
+
<span class="title">TestUnit</span>
|
43
|
+
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div id="search">
|
47
|
+
|
48
|
+
<a class="full_list_link" id="class_list_link"
|
49
|
+
href="class_list.html">
|
50
|
+
|
51
|
+
<svg width="24" height="24">
|
52
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
+
</svg>
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<div id="content"><h1>Module: TestUnit
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<dl>
|
80
|
+
<dt>Defined in:</dt>
|
81
|
+
<dd>lib/generators/test_unit/form_generator.rb</dd>
|
82
|
+
</dl>
|
83
|
+
|
84
|
+
</div>
|
85
|
+
|
86
|
+
<h2>Defined Under Namespace</h2>
|
87
|
+
<p class="children">
|
88
|
+
|
89
|
+
|
90
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="TestUnit/Generators.html" title="TestUnit::Generators (module)">Generators</a></span>
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
</p>
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
</div>
|
106
|
+
|
107
|
+
<div id="footer">
|
108
|
+
Generated on Mon Jan 13 17:26:04 2025 by
|
109
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
110
|
+
0.9.37 (ruby-3.3.1).
|
111
|
+
</div>
|
112
|
+
|
113
|
+
</div>
|
114
|
+
</body>
|
115
|
+
</html>
|
data/docs/_index.html
CHANGED
@@ -117,6 +117,25 @@
|
|
117
117
|
|
118
118
|
</li>
|
119
119
|
|
120
|
+
<li>
|
121
|
+
<span class='object_link'><a href="FormGenerator.html" title="FormGenerator (class)">FormGenerator</a></span>
|
122
|
+
|
123
|
+
</li>
|
124
|
+
|
125
|
+
<li>
|
126
|
+
<span class='object_link'><a href="Rspec/Generators/FormGenerator.html" title="Rspec::Generators::FormGenerator (class)">FormGenerator</a></span>
|
127
|
+
|
128
|
+
<small>(Rspec::Generators)</small>
|
129
|
+
|
130
|
+
</li>
|
131
|
+
|
132
|
+
<li>
|
133
|
+
<span class='object_link'><a href="TestUnit/Generators/FormGenerator.html" title="TestUnit::Generators::FormGenerator (class)">FormGenerator</a></span>
|
134
|
+
|
135
|
+
<small>(TestUnit::Generators)</small>
|
136
|
+
|
137
|
+
</li>
|
138
|
+
|
120
139
|
</ul>
|
121
140
|
</ul>
|
122
141
|
|
@@ -132,6 +151,20 @@
|
|
132
151
|
|
133
152
|
</li>
|
134
153
|
|
154
|
+
<li>
|
155
|
+
<span class='object_link'><a href="Rspec/Generators.html" title="Rspec::Generators (module)">Generators</a></span>
|
156
|
+
|
157
|
+
<small>(Rspec)</small>
|
158
|
+
|
159
|
+
</li>
|
160
|
+
|
161
|
+
<li>
|
162
|
+
<span class='object_link'><a href="TestUnit/Generators.html" title="TestUnit::Generators (module)">Generators</a></span>
|
163
|
+
|
164
|
+
<small>(TestUnit)</small>
|
165
|
+
|
166
|
+
</li>
|
167
|
+
|
135
168
|
</ul>
|
136
169
|
</ul>
|
137
170
|
|
@@ -163,6 +196,35 @@
|
|
163
196
|
</ul>
|
164
197
|
</ul>
|
165
198
|
|
199
|
+
|
200
|
+
<ul id="alpha_R" class="alpha">
|
201
|
+
<li class="letter">R</li>
|
202
|
+
<ul>
|
203
|
+
|
204
|
+
<li>
|
205
|
+
<span class='object_link'><a href="Rspec.html" title="Rspec (module)">Rspec</a></span>
|
206
|
+
|
207
|
+
</li>
|
208
|
+
|
209
|
+
</ul>
|
210
|
+
</ul>
|
211
|
+
|
212
|
+
|
213
|
+
</td><td valign='top' width="33%">
|
214
|
+
|
215
|
+
|
216
|
+
<ul id="alpha_T" class="alpha">
|
217
|
+
<li class="letter">T</li>
|
218
|
+
<ul>
|
219
|
+
|
220
|
+
<li>
|
221
|
+
<span class='object_link'><a href="TestUnit.html" title="TestUnit (module)">TestUnit</a></span>
|
222
|
+
|
223
|
+
</li>
|
224
|
+
|
225
|
+
</ul>
|
226
|
+
</ul>
|
227
|
+
|
166
228
|
</td>
|
167
229
|
</tr>
|
168
230
|
</table>
|
@@ -172,7 +234,7 @@
|
|
172
234
|
</div>
|
173
235
|
|
174
236
|
<div id="footer">
|
175
|
-
Generated on
|
237
|
+
Generated on Mon Jan 13 17:26:03 2025 by
|
176
238
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
177
239
|
0.9.37 (ruby-3.3.1).
|
178
240
|
</div>
|
data/docs/class_list.html
CHANGED
@@ -46,7 +46,7 @@
|
|
46
46
|
|
47
47
|
<ul id="full_list" class="class">
|
48
48
|
<li id="object_" class="odd"><div class="item" style="padding-left:30px"><span class='object_link'><a href="top-level-namespace.html" title="Top Level Namespace (root)">Top Level Namespace</a></span></div></li>
|
49
|
-
<li id='
|
49
|
+
<li id='object_FormGenerator' class='even'><div class='item' style='padding-left:30px'><span class='object_link'><a href="FormGenerator.html" title="FormGenerator (class)">FormGenerator</a></span> < NamedBase<small class='search_info'>Top Level Namespace</small></div></li><li id='object_HyperActiveForm' class='odd'><div class='item' style='padding-left:30px'><a tabindex='0' class='toggle' role='button' aria-label='HyperActiveForm child nodes' aria-expanded='false' aria-controls='object_HyperActiveForm'></a> <span class='object_link'><a href="HyperActiveForm.html" title="HyperActiveForm (module)">HyperActiveForm</a></span><small class='search_info'>Top Level Namespace</small></div><div aria-labelledby='object_HyperActiveForm'><ul><li id='object_HyperActiveForm::Base' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="HyperActiveForm/Base.html" title="HyperActiveForm::Base (class)">Base</a></span> < Object<small class='search_info'>HyperActiveForm</small></div></li><li id='object_HyperActiveForm::CancelFormSubmit' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="HyperActiveForm/CancelFormSubmit.html" title="HyperActiveForm::CancelFormSubmit (class)">CancelFormSubmit</a></span> < StandardError<small class='search_info'>HyperActiveForm</small></div></li><li id='object_HyperActiveForm::FormDidNotSubmitError' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="HyperActiveForm/FormDidNotSubmitError.html" title="HyperActiveForm::FormDidNotSubmitError (class)">FormDidNotSubmitError</a></span> < StandardError<small class='search_info'>HyperActiveForm</small></div></li><li id='object_HyperActiveForm::Generators' class='collapsed odd'><div class='item' style='padding-left:45px'><a tabindex='0' class='toggle' role='button' aria-label='Generators child nodes' aria-expanded='false' aria-controls='object_HyperActiveForm::Generators'></a> <span class='object_link'><a href="HyperActiveForm/Generators.html" title="HyperActiveForm::Generators (module)">Generators</a></span><small class='search_info'>HyperActiveForm</small></div><div aria-labelledby='object_HyperActiveForm::Generators'><ul><li id='object_HyperActiveForm::Generators::InstallGenerator' class='collapsed'><div class='item' style='padding-left:60px'><span class='object_link'><a href="HyperActiveForm/Generators/InstallGenerator.html" title="HyperActiveForm::Generators::InstallGenerator (class)">InstallGenerator</a></span> < Base<small class='search_info'>HyperActiveForm::Generators</small></div></li></ul></div></li></ul></div></li><li id='object_Rspec' class='even'><div class='item' style='padding-left:30px'><a tabindex='0' class='toggle' role='button' aria-label='Rspec child nodes' aria-expanded='false' aria-controls='object_Rspec'></a> <span class='object_link'><a href="Rspec.html" title="Rspec (module)">Rspec</a></span><small class='search_info'>Top Level Namespace</small></div><div aria-labelledby='object_Rspec'><ul><li id='object_Rspec::Generators' class='collapsed odd'><div class='item' style='padding-left:45px'><a tabindex='0' class='toggle' role='button' aria-label='Generators child nodes' aria-expanded='false' aria-controls='object_Rspec::Generators'></a> <span class='object_link'><a href="Rspec/Generators.html" title="Rspec::Generators (module)">Generators</a></span><small class='search_info'>Rspec</small></div><div aria-labelledby='object_Rspec::Generators'><ul><li id='object_Rspec::Generators::FormGenerator' class='collapsed'><div class='item' style='padding-left:60px'><span class='object_link'><a href="Rspec/Generators/FormGenerator.html" title="Rspec::Generators::FormGenerator (class)">FormGenerator</a></span> < NamedBase<small class='search_info'>Rspec::Generators</small></div></li></ul></div></li></ul></div></li><li id='object_TestUnit' class='even'><div class='item' style='padding-left:30px'><a tabindex='0' class='toggle' role='button' aria-label='TestUnit child nodes' aria-expanded='false' aria-controls='object_TestUnit'></a> <span class='object_link'><a href="TestUnit.html" title="TestUnit (module)">TestUnit</a></span><small class='search_info'>Top Level Namespace</small></div><div aria-labelledby='object_TestUnit'><ul><li id='object_TestUnit::Generators' class='collapsed odd'><div class='item' style='padding-left:45px'><a tabindex='0' class='toggle' role='button' aria-label='Generators child nodes' aria-expanded='false' aria-controls='object_TestUnit::Generators'></a> <span class='object_link'><a href="TestUnit/Generators.html" title="TestUnit::Generators (module)">Generators</a></span><small class='search_info'>TestUnit</small></div><div aria-labelledby='object_TestUnit::Generators'><ul><li id='object_TestUnit::Generators::FormGenerator' class='collapsed'><div class='item' style='padding-left:60px'><span class='object_link'><a href="TestUnit/Generators/FormGenerator.html" title="TestUnit::Generators::FormGenerator (class)">FormGenerator</a></span> < NamedBase<small class='search_info'>TestUnit::Generators</small></div></li></ul></div></li></ul></div></li>
|
50
50
|
|
51
51
|
</ul>
|
52
52
|
</div>
|
data/docs/file.README.html
CHANGED
@@ -87,6 +87,15 @@
|
|
87
87
|
|
88
88
|
<p>this will create an <code>ApplicationForm</code> class in your app/forms directory. You can use it as a base class for your form objects.</p>
|
89
89
|
|
90
|
+
<h2 id="label-Generators">Generators</h2>
|
91
|
+
|
92
|
+
<p>You can <a href="https://guides.rubyonrails.org/configuring.html#configuring-generators">generate</a> a form and its tests with the following command:</p>
|
93
|
+
|
94
|
+
<pre class="code ruby"><code class="ruby">$ rails generate form FooBar
|
95
|
+
</code></pre>
|
96
|
+
|
97
|
+
<p>This will create the <code>FooBarForm</code></p>
|
98
|
+
|
90
99
|
<h2 id="label-Usage">Usage</h2>
|
91
100
|
|
92
101
|
<p>Here is an example of an <code>HyperActiveForm</code> form object:</p>
|
@@ -257,11 +266,40 @@
|
|
257
266
|
|
258
267
|
<p>And in the controller:</p>
|
259
268
|
|
260
|
-
<
|
269
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>UsersController</span> <span class='op'><</span> <span class='const'>ApplicationController</span>
|
270
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_index'>index</span>
|
271
|
+
<span class='ivar'>@form</span> <span class='op'>=</span> <span class='const'>UserSearchForm</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
272
|
+
<span class='ivar'>@form</span><span class='period'>.</span><span class='id identifier rubyid_submit!'>submit!</span><span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:user</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
273
|
+
<span class='ivar'>@users</span> <span class='op'>=</span> <span class='ivar'>@form</span><span class='period'>.</span><span class='id identifier rubyid_results'>results</span>
|
274
|
+
<span class='kw'>end</span>
|
275
|
+
<span class='kw'>end</span>
|
276
|
+
</code></pre>
|
277
|
+
|
278
|
+
<h2 id="label-Callbacks">Callbacks</h2>
|
279
|
+
|
280
|
+
<p>HyperActiveForm provides callbacks for <code>assign_form_attributes</code> and <code>submit</code>.</p>
|
281
|
+
|
282
|
+
<p>You can use these callbacks to run code before or after assigning the form attributes or before or after submitting the form.</p>
|
283
|
+
|
284
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>ProfileForm</span> <span class='op'><</span> <span class='const'>ApplicationForm</span>
|
285
|
+
<span class='comment'># ...
|
286
|
+
</span>
|
287
|
+
<span class='id identifier rubyid_before_submit'>before_submit</span> <span class='symbol'>:do_something_before_submit</span>
|
288
|
+
<span class='id identifier rubyid_before_assign_form_attributes'>before_assign_form_attributes</span> <span class='symbol'>:do_something_before_assign_form_attributes</span>
|
289
|
+
|
290
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_do_something_before_submit'>do_something_before_submit</span>
|
291
|
+
<span class='comment'># Do something before submitting the form
|
292
|
+
</span> <span class='kw'>end</span>
|
293
|
+
|
294
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_do_something_before_assign_form_attributes'>do_something_before_assign_form_attributes</span>
|
295
|
+
<span class='comment'># Do something before assigning the form attributes
|
296
|
+
</span> <span class='kw'>end</span>
|
297
|
+
<span class='kw'>end</span>
|
298
|
+
</code></pre>
|
261
299
|
</div></div>
|
262
300
|
|
263
301
|
<div id="footer">
|
264
|
-
Generated on
|
302
|
+
Generated on Mon Jan 13 17:26:04 2025 by
|
265
303
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
266
304
|
0.9.37 (ruby-3.3.1).
|
267
305
|
</div>
|
data/docs/index.html
CHANGED
@@ -87,6 +87,15 @@
|
|
87
87
|
|
88
88
|
<p>this will create an <code>ApplicationForm</code> class in your app/forms directory. You can use it as a base class for your form objects.</p>
|
89
89
|
|
90
|
+
<h2 id="label-Generators">Generators</h2>
|
91
|
+
|
92
|
+
<p>You can <a href="https://guides.rubyonrails.org/configuring.html#configuring-generators">generate</a> a form and its tests with the following command:</p>
|
93
|
+
|
94
|
+
<pre class="code ruby"><code class="ruby">$ rails generate form FooBar
|
95
|
+
</code></pre>
|
96
|
+
|
97
|
+
<p>This will create the <code>FooBarForm</code></p>
|
98
|
+
|
90
99
|
<h2 id="label-Usage">Usage</h2>
|
91
100
|
|
92
101
|
<p>Here is an example of an <code>HyperActiveForm</code> form object:</p>
|
@@ -257,11 +266,40 @@
|
|
257
266
|
|
258
267
|
<p>And in the controller:</p>
|
259
268
|
|
260
|
-
<
|
269
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>UsersController</span> <span class='op'><</span> <span class='const'>ApplicationController</span>
|
270
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_index'>index</span>
|
271
|
+
<span class='ivar'>@form</span> <span class='op'>=</span> <span class='const'>UserSearchForm</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
272
|
+
<span class='ivar'>@form</span><span class='period'>.</span><span class='id identifier rubyid_submit!'>submit!</span><span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span><span class='lbracket'>[</span><span class='symbol'>:user</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
273
|
+
<span class='ivar'>@users</span> <span class='op'>=</span> <span class='ivar'>@form</span><span class='period'>.</span><span class='id identifier rubyid_results'>results</span>
|
274
|
+
<span class='kw'>end</span>
|
275
|
+
<span class='kw'>end</span>
|
276
|
+
</code></pre>
|
277
|
+
|
278
|
+
<h2 id="label-Callbacks">Callbacks</h2>
|
279
|
+
|
280
|
+
<p>HyperActiveForm provides callbacks for <code>assign_form_attributes</code> and <code>submit</code>.</p>
|
281
|
+
|
282
|
+
<p>You can use these callbacks to run code before or after assigning the form attributes or before or after submitting the form.</p>
|
283
|
+
|
284
|
+
<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'>ProfileForm</span> <span class='op'><</span> <span class='const'>ApplicationForm</span>
|
285
|
+
<span class='comment'># ...
|
286
|
+
</span>
|
287
|
+
<span class='id identifier rubyid_before_submit'>before_submit</span> <span class='symbol'>:do_something_before_submit</span>
|
288
|
+
<span class='id identifier rubyid_before_assign_form_attributes'>before_assign_form_attributes</span> <span class='symbol'>:do_something_before_assign_form_attributes</span>
|
289
|
+
|
290
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_do_something_before_submit'>do_something_before_submit</span>
|
291
|
+
<span class='comment'># Do something before submitting the form
|
292
|
+
</span> <span class='kw'>end</span>
|
293
|
+
|
294
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_do_something_before_assign_form_attributes'>do_something_before_assign_form_attributes</span>
|
295
|
+
<span class='comment'># Do something before assigning the form attributes
|
296
|
+
</span> <span class='kw'>end</span>
|
297
|
+
<span class='kw'>end</span>
|
298
|
+
</code></pre>
|
261
299
|
</div></div>
|
262
300
|
|
263
301
|
<div id="footer">
|
264
|
-
Generated on
|
302
|
+
Generated on Mon Jan 13 17:26:04 2025 by
|
265
303
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
266
304
|
0.9.37 (ruby-3.3.1).
|
267
305
|
</div>
|
data/docs/method_list.html
CHANGED
@@ -64,6 +64,14 @@
|
|
64
64
|
|
65
65
|
|
66
66
|
<li class="odd ">
|
67
|
+
<div class="item">
|
68
|
+
<span class='object_link'><a href="HyperActiveForm/Base.html#assigned_attribute_names-instance_method" title="HyperActiveForm::Base#assigned_attribute_names (method)">#assigned_attribute_names</a></span>
|
69
|
+
<small>HyperActiveForm::Base</small>
|
70
|
+
</div>
|
71
|
+
</li>
|
72
|
+
|
73
|
+
|
74
|
+
<li class="even ">
|
67
75
|
<div class="item">
|
68
76
|
<span class='object_link'><a href="HyperActiveForm/Generators/InstallGenerator.html#create_application_form-instance_method" title="HyperActiveForm::Generators::InstallGenerator#create_application_form (method)">#create_application_form</a></span>
|
69
77
|
<small>HyperActiveForm::Generators::InstallGenerator</small>
|
@@ -71,6 +79,30 @@
|
|
71
79
|
</li>
|
72
80
|
|
73
81
|
|
82
|
+
<li class="odd ">
|
83
|
+
<div class="item">
|
84
|
+
<span class='object_link'><a href="FormGenerator.html#create_application_form-instance_method" title="FormGenerator#create_application_form (method)">#create_application_form</a></span>
|
85
|
+
<small>FormGenerator</small>
|
86
|
+
</div>
|
87
|
+
</li>
|
88
|
+
|
89
|
+
|
90
|
+
<li class="even ">
|
91
|
+
<div class="item">
|
92
|
+
<span class='object_link'><a href="Rspec/Generators/FormGenerator.html#create_form_spec-instance_method" title="Rspec::Generators::FormGenerator#create_form_spec (method)">#create_form_spec</a></span>
|
93
|
+
<small>Rspec::Generators::FormGenerator</small>
|
94
|
+
</div>
|
95
|
+
</li>
|
96
|
+
|
97
|
+
|
98
|
+
<li class="odd ">
|
99
|
+
<div class="item">
|
100
|
+
<span class='object_link'><a href="TestUnit/Generators/FormGenerator.html#create_form_test-instance_method" title="TestUnit::Generators::FormGenerator#create_form_test (method)">#create_form_test</a></span>
|
101
|
+
<small>TestUnit::Generators::FormGenerator</small>
|
102
|
+
</div>
|
103
|
+
</li>
|
104
|
+
|
105
|
+
|
74
106
|
<li class="even ">
|
75
107
|
<div class="item">
|
76
108
|
<span class='object_link'><a href="HyperActiveForm/Base.html#initialize-instance_method" title="HyperActiveForm::Base#initialize (method)">#initialize</a></span>
|
@@ -82,10 +82,12 @@
|
|
82
82
|
<p class="children">
|
83
83
|
|
84
84
|
|
85
|
-
<strong class="modules">Modules:</strong> <span class='object_link'><a href="HyperActiveForm.html" title="HyperActiveForm (module)">HyperActiveForm</a></span>
|
85
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="HyperActiveForm.html" title="HyperActiveForm (module)">HyperActiveForm</a></span>, <span class='object_link'><a href="Rspec.html" title="Rspec (module)">Rspec</a></span>, <span class='object_link'><a href="TestUnit.html" title="TestUnit (module)">TestUnit</a></span>
|
86
86
|
|
87
87
|
|
88
88
|
|
89
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="FormGenerator.html" title="FormGenerator (class)">FormGenerator</a></span>
|
90
|
+
|
89
91
|
|
90
92
|
</p>
|
91
93
|
|
@@ -100,7 +102,7 @@
|
|
100
102
|
</div>
|
101
103
|
|
102
104
|
<div id="footer">
|
103
|
-
Generated on
|
105
|
+
Generated on Mon Jan 13 17:26:04 2025 by
|
104
106
|
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
105
107
|
0.9.37 (ruby-3.3.1).
|
106
108
|
</div>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Rspec
|
2
|
+
module Generators
|
3
|
+
class FormGenerator < ::Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path("templates", __dir__)
|
5
|
+
|
6
|
+
def create_form_spec
|
7
|
+
template "form_spec.rb", File.join("spec/forms", class_path, "#{file_name}_form_spec.rb")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module TestUnit
|
2
|
+
module Generators
|
3
|
+
class FormGenerator < ::Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path("templates", __dir__)
|
5
|
+
|
6
|
+
def create_form_test
|
7
|
+
template "form_test.rb", File.join("test/forms", class_path, "#{file_name}_form_test.rb")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -19,6 +19,10 @@ module HyperActiveForm
|
|
19
19
|
|
20
20
|
define_model_callbacks :assign_form_attributes, :submit
|
21
21
|
|
22
|
+
# The list of attribute names that have been passed to the form
|
23
|
+
# during the last call to `assign_form_attributes` or `submit`
|
24
|
+
attr_reader :assigned_attribute_names
|
25
|
+
|
22
26
|
# Defines to which object the form should delegate the active model methods
|
23
27
|
# This is useful so `form_for`/`form_with` can automatically deduce the url and method to use
|
24
28
|
#
|
@@ -53,6 +57,7 @@ module HyperActiveForm
|
|
53
57
|
default_value = self.class._default_attributes[attribute]&.value_before_type_cast
|
54
58
|
public_send(:"#{attribute}=", params&.dig(attribute) || default_value)
|
55
59
|
end
|
60
|
+
@assigned_attribute_names = params.slice(*attribute_names).keys
|
56
61
|
end
|
57
62
|
end
|
58
63
|
|
data/lib/hyper_active_form.rb
CHANGED