You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can pass additional parameters to the options endpoint:
@@ -223,6 +278,67 @@ argument:
223
278
end
224
279
```
225
280
281
+
#### Path options for nested resources
282
+
283
+
Example for the following setup:
284
+
285
+
```ruby
286
+
# Models
287
+
classOptionType < ActiveRecord::Base; end
288
+
289
+
classOptionValue < ActiveRecord::Base
290
+
belongs_to :option_type
291
+
end
292
+
293
+
classProduct < ActiveRecord::Base
294
+
belongs_to :option_type
295
+
has_many :variants
296
+
end
297
+
298
+
classVariant < ActiveRecord::Base
299
+
belongs_to :product
300
+
belongs_to :option_value
301
+
end
302
+
303
+
# ActiveAdmin
304
+
ActiveAdmin.register(OptionType)
305
+
306
+
ActiveAdmin.register(Product)
307
+
308
+
ActiveAdmin.register(OptionValue) do
309
+
belongs_to :option_type
310
+
searchable_select_options(scope:lambdado |params|
311
+
OptionValue.where(
312
+
option_type_id: params[:option_type_id]
313
+
)
314
+
end,
315
+
text_attribute::value)
316
+
end
317
+
```
318
+
319
+
It is possible to pass path parameters for correctly generating URLs for nested resources fetching via `path_params`
320
+
321
+
```ruby
322
+
ActiveAdmin.register(Variant) do
323
+
belongs_to :product
324
+
325
+
form do |f|
326
+
...
327
+
f.input(:option_value,
328
+
as::searchable_select,
329
+
ajax: {
330
+
resource:OptionValue,
331
+
path_params: {
332
+
option_type_id: f.object.product.option_type_id
333
+
}
334
+
})
335
+
...
336
+
end
337
+
end
338
+
```
339
+
340
+
This will generate the path for fetching as `all_options_admin_option_type_option_values(option_type_id: f.object.product.option_type_id)` (e.g. `/admin/option_types/2/option_values/all_options`)
341
+
226
342
#### Inlining Ajax Options in Feature Tests
227
343
228
344
When writing UI driven feature specs (i.e. with Capybara),
0 commit comments