简体   繁体   中英

How do I add a custom field with label, but without input tag?

I have a form which in code looks like that:

= simple_form_for @cat do |f|
  = f.input :lives
  = f.input :whiskers

Which renders all appropriate labels, wrap in divs with correct classes and at the end I get form like that:

+------------------------------+
|          Cat Manager         |
|--------------+---------------|
|              |+-------------+|
|        Lives:||            9||
|              |+-------------+|
|              |+-------------+|
|     Whiskers:||         many||
|              |+-------------+|
+--------------v---------------+

Now I want to add some information to show to user as reference. I know that I can look up correct html wrappers, classes, etc and just add plain html to my form, but this is ugly and if wrappers change I would have to change all corresponding classes manually. So, ideally I would like to have something like that:

= simple_form_for @cat do |f|
  = f.field 'Owner:', @cat.owner.decorate.link_to_profile
  = f.input :lives
  = f.input :whiskers

Which will render a similarly looking form, but with my new field:

+------------------------------+
|          Cat Manager         |
|--------------+---------------|
|              |               |
|        Owner:|:-) Gary       |
|              |               |
|              |+-------------+|
|        Lives:||            9||
|              |+-------------+|
|              |+-------------+|
|     Whiskers:||         many||
|              |+-------------+|
+--------------v---------------+

I can't find anything similar in simple form documentation. Any ideas from where to start?

Unless I'm misunderstanding, the standard builder won't do what you're after. You might find some use from using f.label :owner for the label and then adding some logic for the input only, but that's probably as close as it gets.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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