Forum: Ruby on Rails Using spacer img in menu

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.
6ce7ffd357f24cdbf218a130fd1ef16c?d=identicon&s=25 Jolé (Guest)
on 2007-07-02 23:08
(Received via mailing list)
Hi!

This is what I want....

blog | photos | about

This is what my code gives me.....

blog | photos | about |

The last "|" is to much....

[code]
  <% for page in @menu_pages %>
    <li><%=page%></li>
    <li>|</li>
  <% end %>
[/code]

Is there any way I can get some sort of indication whether the array
@menu_pages has a next element?

-- Jelle
A2c989d2424e0161d9f34c89a37cd145?d=identicon&s=25 Raymond Sneekes (Guest)
on 2007-07-02 23:25
(Received via mailing list)
On Mon, 2007-07-02 at 14:07 -0700, Jolé wrote:
> Hi!
>
> This is what I want....
>
> blog | photos | about
Hi,

I use this:

        <%= render(:partial => 'navbar_item',
                   :collection => @navbar_items,
                   :spacer_template => 'navbar_spacer') %>

With obviously navbar_item displaying an item and the navbar_spacer the
spacer.

Gr. Raymond
--
Raymond Sneekes
Ef3aa7f7e577ea8cd620462724ddf73b?d=identicon&s=25 Rob Biedenharn (Guest)
on 2007-07-02 23:56
(Received via mailing list)
On Jul 2, 2007, at 5:07 PM, Jolé wrote:
> The last "|" is to much....
>
> -- Jelle

<%= @menu_pages.map { |page|
       content_tag(:li, page.to_s)
     }.join(content_tag(:li, '|')) %>

Which should probably be extracted to a helper so you can call:

<%= menu_items_for(@menu_pages, '|') %>

And there will probably be someone who says "you should use do-end
for a multi-line block", but I'm believing (and trying to follow) Jim
Weirich's style of using {} when the value of the block is used and
do-end otherwise (or when precedence dictates).

-Rob

Rob Biedenharn    http://agileconsultingllc.com
Rob@AgileConsultingLLC.com
This topic is locked and can not be replied to.