Read more

Calling a helper method with the same name as your current partial

Henning Koch
April 15, 2011Software engineer at makandra GmbH

Partials always define a local variable with the same name as themselves. E.g. when you are in _recent_users.html.erb, a local variable recent_users will be defined and overshadow any helper method that is also called recent_users().

Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

If you would like to use a helper method recent_users() in a partial _recent_users.html.erb you can say this in the partial template:

<% recent_users = self.recent_users() %>
<% recent_users.each do |user| %>
  ...
<% end %>
Posted by Henning Koch to makandra dev (2011-04-15 12:14)