Eliminating .fieldWithErrors for labels

I would like to prevent Rails from wrapping my label tags inside the
fieldWithErrors div.

I found a way to do it, but was hoping that there’s a better solution.

Here’s and example from a git diff that shows what I’ve done:

<% form_for(venue) do |f| %>

- <%= f.label :name %>
- <%= f.text_field :name %> + +

<%= label_tag "venue_name", "Name" %>
+
<%= f.text_field :name %>

This actually does work. Apparently f.label helper does the wrapping of
the errors div, where label_tag does not. However, using label_tag
doesn’t know about the venue object scope so I have to specify that
explicitly, as you can see above.

Also notice that I wrapped both the label and text fields inside their
own divs as well. This was to prevent invalid HTML when Rails wraps the
elements inside

tags when there are errors
on the form.

Is this the the best approach, or is there a better way to get f.label
helper to stop wrapping the labels?

The reason I want this is because I like the standard scaffolding style
of wrapping the fields with a red border, but this is also causing my
labels to have an ugly red background.

I know I could just use normal text and not labels, but I also like the
behavior of true HTML form labels.

Any suggestions would be welcome.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs