Instant Gratification

Write a page for the say application that illustrates the looping you can do in ERb. Discuss

Experiment with adding and removing the minus sign at the end of the ERb <%= %> sequence (i.e., changing %> into -%>, and vice versa. Use your browser’s View → Source option to see the difference. Discuss

A call to the following Ruby method returns a list of all the files in the current directory.

@files = Dir.glob('*')

Use it to set an instance variable in a controller action, and then write the corresponding template that displays the filenames in a list on the browser. Hint: in the ERb examples, we saw how to iterate n times. You can iterate over a collection using something like

<% for file in @files %>  
  file name is: <%= file %> 
<% end %>

You might want to use a ul for the list. Discuss

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License