Simple ERB question

Hello, not sure if this should go here…

Trying to print out the contents of an array with a little bit of
formatting

my array looks like this:

search = “[[67749303, 72756004, 178055737, 398925700, 551708624,
684936218, 846436579, 978955981]]”

search_ary = search.split(",")

now in my erb view file I would like to print something like this to the
html:

67749303

72756004

....etc

what is the best way to do this???

Assign your search array to an instance variable in your controller.

@search_ary = search.split(",")

In your view do:

<% @search_ary.each do |row| %>

<%= row %>

<% end %>

On 26 May 2011 16:14, Benjamin M. [email protected]
wrote:

now in my erb view file I would like to print something like this to the
html:

67749303

72756004

....etc

what is the best way to do this???

Not sure of the “best” way… but there are lots of ways - here’s two:

You could render a collection of partials as described on
http://api.rubyonrails.org/classes/ActionView/Partials.html

You could loop yourself:

<% search_ary.each do |element| %>
<%= content_tag :p, element %>
<% end %>

By the way, did your example array mean to be nested in another array
(two lots of square brackets…)?

On Thu, May 26, 2011 at 8:44 PM, Benjamin M. <
[email protected]> wrote:

<% search.each do |number| %>

<%= number %>

<% end %>

This will give result as below

67749303

72756004

....etc


Regards

sathia
http://www.sathia27.wordpress.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs