Commit dbed9cd 1 parent 030989b commit dbed9cd Copy full SHA for dbed9cd
File tree 1 file changed +52
-0
lines changed
1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -266,6 +266,58 @@ Example:
266
266
# ...
267
267
end
268
268
269
+ DRY with param_group
270
+ --------------------
271
+
272
+ Often, params occur together in more actions. Typically, most of the
273
+ params for ``create `` and ``update `` actions are common for both of
274
+ them.
275
+
276
+ This params can be extracted with ``def_param_group `` and
277
+ ``param_group `` keywords.
278
+
279
+ The definition is looked up in the scope of the controller. If the
280
+ group is defined in a different controller, it might be referenced by
281
+ specifying the second argument.
282
+
283
+ Example:
284
+ ~~~~~~~~
285
+
286
+ .. code :: ruby
287
+
288
+ # v1/users_controller.rb
289
+ def_param_group :address do
290
+ param :street , String
291
+ param :number , Integer
292
+ param :zip , String
293
+ end
294
+
295
+ def_param_group :user do
296
+ param :user , Hash do
297
+ param :name , String , " Name of the user"
298
+ param_group :address
299
+ end
300
+ end
301
+
302
+ api :POST , " /users" , " Create an user"
303
+ param_group :user
304
+ def create
305
+ # ...
306
+ end
307
+
308
+ api :PUT , " /users/:id" , " Update an user"
309
+ param_group :user
310
+ def update
311
+ # ...
312
+ end
313
+
314
+ # v2/users_controller.rb
315
+ api :POST , " /users" , " Create an user"
316
+ param_group :user , V1 ::UsersController
317
+ def create
318
+ # ...
319
+ end
320
+
269
321
270
322
=========================
271
323
Configuration Reference
You can’t perform that action at this time.
0 commit comments