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.
Ead43bcb0202410540a6a7cee5955d46?d=identicon&s=25 Fresh Mix (giga)
on 2009-02-20 22:55
How make a helper:

If value X is true: print <li class="current"> else <li>
6fabb84e727dee98d1277df56458cbac?d=identicon&s=25 Andrew Bloom (Guest)
on 2009-02-20 22: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 Bond <rails-mailing-l...@andreas-s.net>
Ead43bcb0202410540a6a7cee5955d46?d=identicon&s=25 Fresh Mix (giga)
on 2009-02-20 23:20
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 %>
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-02-20 23:33
(Received via mailing list)
On Feb 20, 10:20 pm, James Bond <rails-mailing-l...@andreas-s.net>
wrote:
> 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
Ead43bcb0202410540a6a7cee5955d46?d=identicon&s=25 Fresh Mix (giga)
on 2009-02-24 09: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>
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-02-24 09:17
(Received via mailing list)
On Feb 24, 8:04 am, Jo Jo <rails-mailing-l...@andreas-s.net> 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
Ead43bcb0202410540a6a7cee5955d46?d=identicon&s=25 Fresh Mix (giga)
on 2009-02-24 09:44
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
This topic is locked and can not be replied to.