Leevi Graham
2007-Jan-24 07:14 UTC
Removing empty class attribute from @template.content_tag
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? -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
gmarik
2007-Jan-24 13:20 UTC
Re: Removing empty class attribute from @template.content_tag
how about: :class => ''required'' if required? On Jan 24, 9:14 am, Leevi Graham <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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? > > -- > Posted viahttp://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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---