Helper

How make a helper:

If value X is true: print <li class="current"> else <li>

Try something like this:

def current_li(content, x)   klass = x ? "current" : nil   content_tag(:li, content, :class => klass) end

Andrew Bloom wrote: > def current_li(content, x) > klass = x ? "current" : nil > content_tag(:li, content, :class => klass) > end

Thanks, but why this doesn't work?

<%= current_li {link_to "xxx", :controller => "yyy"}, @x == 1 %>

because you're passing a block that generates a link to . something like current_li link_to(...), @x == 1

would probably work.

Fred

And same for <option> ?

Come on, should be easy enough if you got the previous one :slight_smile: (not to mention that options_for_select etc. do this for you).

Fred

Frederick Cheung wrote:

Come on, should be easy enough if you got the previous one :slight_smile:

Not for me :slight_smile: I can't make it work:

  def current_option(value, content, x)     selec = x ? "selected" : nil     content_tag(:option, content, :value => value, :selected => selec)   end