Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing a readonly input text in Active Admin

I have an association where a code has an influencer. I want to show the influencer username as readonly in the code form.

Right now I'm doing:

form do |f|
f.inputs 'Code' do
  f.input :influencer, input_html: { readonly: true, disabled: true  }, as: :string if !f.object.new_record?

But I get this and I want the influencer name or username.

I need a field displayed. Not the object.

Ideas?

like image 247
Leticia Esperon Avatar asked Oct 15 '25 04:10

Leticia Esperon


1 Answers

I ended up adding this line in the code model

delegate :username, to: :influencer, prefix: true, allow_nil: true

and then this in the form:

f.input :influencer_username,
          label: 'Influencer',
          input_html: { readonly: true, disabled: true },
          as: :string unless f.object.new_record?
like image 87
Leticia Esperon Avatar answered Oct 18 '25 06:10

Leticia Esperon