Sijo_Kg
(Sijo Kg)
20 February 2008 06:52
1
Hi
I have @selected_ciid_and_asso_types ( its content is
3:43,2:65,3:50, )
How can i split it like
3 43
2 65
3 50
These are actually two columns of a table..If i get it like above I can
directly save it to database
Sijo
···
--
Posted via http://www.ruby-forum.com/ .
Dan2
(Dan)
20 February 2008 07:00
2
I'm not sure if i really understand your question but if 3:43,2:65,3:50 is
actually a string i.e. "3:43,2:65,3:50"
then "3:43,2:65,3:50".gsub(':',' ').split(',') will return an array
containing:
["3 43", "2 65", "3 50"]
···
On Feb 20, 2008 5:22 PM, Sijo Kg <sijo@maxxion.com> wrote:
Hi
I have @selected_ciid_and_asso_types ( its content is
, )
How can i split it like
3 43
2 65
3 50
These are actually two columns of a table..If i get it like above I can
directly save it to database
Sijo
--
Posted via http://www.ruby-forum.com/\ .
Hi,
I'm not sure if i really understand your question but if 3:43,2:65,3:50 is
actually a string i.e. "3:43,2:65,3:50"
then "3:43,2:65,3:50".gsub(':',' ').split(',') will return an array
containing:
["3 43", "2 65", "3 50"]
If they're two columns of a database, then this will probably be more
helpful:
rows = @selected_ciid_and_asso_types.split (',').map {|e| e.split(':')}
=> [["3", "43"], ["2", "65"], ["3", "50"]]
You could also change the last bit to e.split(':').map {|s| s.to_i} if you
wanted [[3, 43], [2, 65], [3, 50]] instead.
Arlen
···
On Feb 20, 2008 6:00 PM, Dan <dan.macdaddy+ruby@gmail.com> wrote:
Sijo_Kg
(Sijo Kg)
20 February 2008 07:39
4
Hi
This is working..But what I need is like
ci_id service_desk_ci_id
3 43
2 65
3 50
Then with in a for loop
@obj.ci_id=3
@obj.service_desk_ci_id=43
@obj.ci_id=2
@obj.service_desk_ci_id=65
@obj.ci_id=3
@obj.service_desk_ci_id=50
How can i do this ?
Sijo
···
--
Posted via http://www.ruby-forum.com/ .
Hi,
rows = @selected_ciid_and_asso_types.split (',').map {|e| e.split(':').map
{|s| s.to_i}}
rows.each do |r|
obj = make_obj_somehow()
obj.ci_id, obj.service_desk_ci_id = r
end
Something like this?
Arlen
Sijo_Kg
(Sijo Kg)
20 February 2008 08:00
6
Hi
Thanks a lot..It is working..To get more understanding of all these
can u suggest me a good book or online tutorial..I am a beginner to
rails
Sijo
···
--
Posted via http://www.ruby-forum.com/ .
Hi there,
For Rails, try Agile Web Development with Rails: A Pragmatic Guide - it got
me off the ground in Rails, but you'll still need to put in effort to grasp
the situation clearly. Learning the ins and outs of Ruby is important.
Arlen
Sijo_Kg
(Sijo Kg)
20 February 2008 08:09
8
Thanks again .For ruby learning may you suggest a good book
Sijo
···
--
Posted via http://www.ruby-forum.com/ .
7stud
(7stud --)
20 February 2008 08:45
9
Sijo Kg wrote:
Thanks again .For ruby learning may you suggest a good book
Sijo
Consider the new book:
The Ruby Programming Language
One of the authors, David Flanagan, previously wrote 'the' book for
Javascript programming, so I would expect this book to be top notch.
···
--
Posted via http://www.ruby-forum.com/\ .