hey everyone i want to split the array.This is the out put when i
print array "Khamar Md,2 hrs: 5 min,Accounts,Gandhinagar" and i wanna
split them and i want to print them in different columns in a table.
<%x=Array.new%>
(",")%>
<% x.each do |late_commer| %>
<td><%= late_commer.at(0) %></td>
<%end%>

when i use the about code i get Khamar Md,2 hrs: 5
min,Accounts,Gandhinagar in one column only . i want them in different
columns like
Name | Time | Dept | Loc
-------------------------------------------------------------------------
Khamar Md 2 hrs: 5 min Accounts Gandhinagar
Dis is the Output i need.Can any one help out how to split the array
plz..


Thanks in Advance guys

--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Greg Akins at Dec 23, 2011 at 5:56 pm

    On Fri, Dec 23, 2011 at 12:28 PM, honey ruby wrote:
    hey everyone i want to split the array.This is the out put when i
    print array "Khamar  Md,2 hrs: 5 min,Accounts,Gandhinagar" and i wanna
    split them and i want to print them in different columns in a table.
    <%x=Array.new%>
    (",")%>
    <% x.each do |late_commer|  %>
    <td><%= late_commer.at(0) %></td>
    <%end%>
    This works for me. No need to declare x as Array.new.. that's going
    to happen when you assign it the value of late_commers.split

    Why the late_commer.at(0) if late_commer is the value of an individual
    string? Are you sure that late_commers is a string to begin with?

    irb(main):001:0> x = "This, is, a, test"
    => "This, is, a, test"
    irb(main):002:0> y = x.split(",")
    => ["This", " is", " a", " test"]
    irb(main):003:0> y.each do |z|
    irb(main):004:1* puts z
    irb(main):005:1> end
    This
    is
    a
    test
    => ["This", " is", " a", " test"]
    irb(main):006:0>


    --
    Greg Akins
    http://twitter.com/akinsgre

    --
    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@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Alex Mercer at Dec 24, 2011 at 2:40 pm
    honey ruby, c'mon.. Did you know about such things like controllers?
    Passing whole work with arrays in views it's a bad idea.

    # app/controllers/my_controller.rb
    class MyController < ApplicationController
    def commers
    @late_commers = "Khamar Md,2 hrs: 5
    min,Accounts,Gandhinagar".split(",")
    end
    end

    # app/views/my/commers.html.erb
    ..
    <table>
    ..
    <% @late_commers.each do |late_commer| %>
    <td><%= late_commer %></td>
    <%end%>
    ..
    </table>
    ..

    No need to declare x as Array.new.
    You're right. There is no need to declare it case split returning an
    array.
    Why the late_commer.at(0) if late_commer is the value of an individual
    string? Are you sure that late_commers is a string to begin with?
    Greg, +1
    honey, you're trying to get each item(that is a string object in this
    case) from array.
    And it doesn't have such method like 'at'
    On Dec 23, 7:56 pm, Greg Akins wrote:
    On Fri, Dec 23, 2011 at 12:28 PM, honey ruby wrote:
    hey everyone i want to split the array.This is the out put when i
    print array "Khamar  Md,2 hrs: 5 min,Accounts,Gandhinagar" and i wanna
    split them and i want to print them in different columns in a table.
    <%x=Array.new%>
    (",")%>
    <% x.each do |late_commer|  %>
    <td><%= late_commer.at(0) %></td>
    <%end%>
    This works for me.  No need to declare x as Array.new.. that's going
    to happen when you assign it the value of late_commers.split

    Why the late_commer.at(0) if late_commer is the value of an individual
    string?  Are you sure that late_commers is a string to begin with?

    irb(main):001:0> x = "This, is, a, test"
    => "This, is, a, test"
    irb(main):002:0> y = x.split(",")
    => ["This", " is", " a", " test"]
    irb(main):003:0> y.each do |z|
    irb(main):004:1* puts z
    irb(main):005:1> end
    This
    is
    a
    test
    => ["This", " is", " a", " test"]
    irb(main):006:0>

    --
    Greg Akinshttp://twitter.com/akinsgre
    --
    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@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedDec 23, '11 at 5:29p
activeDec 24, '11 at 2:40p
posts3
users3
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2021 Grokbase