Helper


#1

How make a helper:

If value X is true: print

  • else

  • #2

    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. removed_email_address@domain.invalid


    #3

    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 %>


    #4

    On Feb 20, 10:20 pm, James B. removed_email_address@domain.invalid
    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


    #5

    And same for ?

    selected_option (value, content, x)

    if x = true then

    content

    else

    content

    #6

    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


    #7

    On Feb 24, 8:04 am, Jo Jo removed_email_address@domain.invalid 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