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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community 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("div",
    @template.content_tag( "span", Example Label ) +
    super,
    :class => (required.nil?) ? '' : 'required'
  )
end

calling:

<%= f.datetime_select :dob  %>

inside:

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

renders the following:

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

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=""
attribute?
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.