How make a helper:
If value X is true: print <li class="current"> else <li>
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 (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
Not for me
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