Thoughts, information and reflections about technology

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

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.

Similar Posts:

Leave a Reply

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

Contact me
Archives
Categories
Amazon Disclosure

We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites.