Forum: Ruby on Rails Removing empty class attribute from @template.content_tag

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Leevi G. (Guest)
on 2007-01-24 09:14
Hey all,

I have a quick question regarding the @template.content_tag methos when
creating a custom form builder.

Currently have the following method in my AccessibleBuilder class:

def datetime_select(field, options = {})
  required = options.delete :required
  label = options.delete :label
    @template.content_tag( "span", Example Label ) +
    :class => (required.nil?) ? '' : 'required'


<%= f.datetime_select :dob  %>


<% form_for :person, :builder => AccessibleBuilder do |f| %>

renders the following:

<div class="">
  <span>Example Label<small>*</small>: </span>
  <select> ... </select>

Any ideas how I can add a conditional somewhere to only render the
:class=>"" if the field is required rather than have the empty class=""
gmarik (Guest)
on 2007-01-24 15:20
(Received via mailing list)
how about:
:class => 'required' if required?

On Jan 24, 9:14 am, Leevi G. <removed_email_address@domain.invalid>
This topic is locked and can not be replied to.