Helper

How make a helper:

If value X is true: print

  • else
  • Try something like this:

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

    On Feb 20, 3:55 pm, James B. [email protected]

    Andrew B. 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 %>

    On Feb 20, 10:20 pm, James B. [email protected]
    wrote:

    Andrew B. 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 ?

    selected_option (value, content, x)

    if x = true then

    content

    else

    content

    Frederick C. 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

    On Feb 24, 8:04 am, Jo Jo [email protected] wrote:

    And same for ?

    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