Home > Enterprise >  Administrate gem — Pass custom HTML classes into fields
Administrate gem — Pass custom HTML classes into fields

Time:03-21

I use Rails 7, Ruby 2.7, the administrate gem for my admin dashboard and tailwindcss for the frontend.

I am trying to pass custom HTML classes into the fields. I have already generated the partials for all field types using the command rails generate administrate:views:field all.

For example, in app\views\fields\string\_form, how could I add to the input field a tailwind class? Below is a part of the generated file.

<div >
  <%= f.text_field field.attribute %>
</div>

The doc stipulates that there is an instance method called html_class inherited from Base but I struggle to apply it to the view.

Something like this would be perfect:

  • field.attribute.html_class("class1 class2 class3")
  • field.attribute.with_options(html_class: "class1 class2 class3")

CodePudding user response:

Woah ok, this was much easier than what I thought. I had to add the classes this way:

<div >
  <%= f.text_field field.attribute, class: "class1 class2 class3" %>
</div>
  • Related