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???
benni
2
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 %>
benni
3
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…)?
benni
4
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