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:
<p>67749303</p>
<p>72756004</p>
....etc
what is the best way to do this???
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On 26 May 2011 16:14, Benjamin Mulaosmanovic <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> now in my erb view file I would like to print something like this to the > html: > > <p>67749303</p> > <p>72756004</p> > ....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...)? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Assign your search array to an instance variable in your controller.
@search_ary = search.split(",")
In your view do:
<% @search_ary.each do |row| %>
<p><%= row %></p>
<% end %>
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On Thu, May 26, 2011 at 8:44 PM, Benjamin Mulaosmanovic < lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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.each do |number| %> <p><%= number %></p> <% end %> This will give result as below> > <p>67749303</p> > <p>72756004</p> > ....etc > > >-- Regards sathia http://www.sathia27.wordpress.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.