December 15

0 comments

Rails – Passing several discrete items to a ..each do |xxx|

By Christopher Mendla

December 15, 2016


Last Updated on November 30, 2019 by Christopher G Mendla

I had a situation where I wanted to pass a handful of objects to an .each do in Rails such as the points of the compass.

I didn’t find any useful documentation on how to do that. It dawned on me that I could probably set up a simple array and add the .each do to it. 

Below is a sample of how this word work in a view. 

<% [“North”, “East”, “South”, “West” ].each do |compass| %>
                <%= compass %>
<% end %>

The results would be North East South West.
The usefulness of this is limited to those times when you have a small number of items that will not change.

Christopher Mendla

About the author

Leave a Reply

Your email address will not be published. Required fields are marked

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}