On Apr 19, 2009, at 5:51 PM, Joshua Muheim wrote:
>
> Hi all
>
> The cycle() method is very handy in views. But is there some sort of
> only_first_time() that returns the passed value only the first time it
> is invoked within a view?
>
> Thanks for help :-)
> Josh
> --
Just write one:
in a helper:
def only_first_time(what)
first_time = @previous_what.nil?
@previous_what ||= what
what if first_time
end
in a view:
<ol>
<% 5.times do |i| -%>
<li>say <%= only_first_time('once') %></li>
<% end -%>
</ol>
the resulting HTML:
<ol>
<li>say once</li>
<li>say </li>
<li>say </li>
<li>say </li>
<li>say </li>
</ol>
-Rob
Rob Biedenharn http://agileconsultingllc.com
[email protected]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---