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| %>

   <p>
-    <%= f.label :name %><br />
-    <%= f.text_field :name %>
+    <!-- TODO: Make the rest of the field look like this one -->
+    <div><%= label_tag "venue_name", "Name" %></div>
+    <div><%= f.text_field :name %></div>
   </p>

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 <div class="fieldWithName"> 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.
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to