简体   繁体   English

在Active Admin中更改只读输入文本

[英]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. 但是我知道了,我想要影响者的名称或用户名。

我需要显示一个字段。不是对象。

Ideas? 想法?

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?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM