Forum: Ruby on Rails Helper

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fresh M. (Guest)
on 2009-02-20 23:55
How make a helper:

If value X is true: print <li class="current"> else <li>
Andrew B. (Guest)
on 2009-02-20 23:59
(Received via mailing list)
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>
Fresh M. (Guest)
on 2009-02-21 00:20
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 %>
Frederick C. (Guest)
on 2009-02-21 00:33
(Received via mailing list)
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
Fresh M. (Guest)
on 2009-02-24 10:04
And same for <option> ?

selected_option (value, content, x)



if x = true then

<option value=value selected="selected">content</option>

else

<option value=value>content</option>
Frederick C. (Guest)
on 2009-02-24 10:17
(Received via mailing list)
On Feb 24, 8:04 am, Jo Jo <removed_email_address@domain.invalid> wrote:
> 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
Fresh M. (Guest)
on 2009-02-24 10:44
Frederick C. 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
This topic is locked and can not be replied to.