Kleber NG
Kleber NG

Reputation: 107

Activeadmin set resource's attributes on action

I want to set a default value for an attribute of the activeadmin resource, so when it renders the form, it will use this value. e.g.: in the action new, I want to set the attribute product of the object order , so the form will come with the product already selected(but leting it to be changed).

Upvotes: 0

Views: 477

Answers (2)

Kleber NG
Kleber NG

Reputation: 107

I accepted Andrey Deineko's answer, but even before I saw it, I've done it in another way: controller do def new @resource_name = ResourceName.new(...)

so, I just defined the action method inside the block controller, creating an instance of the resource with an instance variable named as the ActiveAdmin Resource name.

Upvotes: 0

Andrey Deineko
Andrey Deineko

Reputation: 52357

Just add the value to the form field as follows:

  f.inputs do
    f.input :product, input_html: { value: products_value }

Upvotes: 1

Related Questions