Forum: Ruby on Rails Store find output in a new array

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Remco S. (Guest)
on 2009-02-26 11:17
Hi,

the array below is the output from a find(:all)

[#<Boekingen affnr: "vl999", pnr: "MA5OSG", agent: "monties",
ticket_prijs: #<BigDecimal:b775f4c4,'0.138E3',4(12)>, aantal_pers: 2,
ticket_fees: nil, res_kosten: nil, commissie: nil, ticket_verz: nil,
tax: nil, total_prijs: #<BigDecimal:b775f230,'0.36316E3',8(12)>, bet_id:
nil, vertrek_id: "AMS", bestemming_id: "MAD", airline_id: "HV",
cabinclass: nil, type: nil, eligibility: nil, supplier: nil, heen_datum:
1020204000, terug_datum: 1049061600, outbound_v: nil, outbound_a: nil,
outbound_vluchtnrs: nil, inbound_v: nil, inbound_a: nil,
inbound_vluchtnrs: nil, reis_verz: #<BigDecimal:b775ed08,'0.0',4(8)>,
annu_verz: #<BigDecimal:b775eccc,'0.0',4(8)>, boeking_status: nil,
enquete_status: 1, holiday_status: 0, eurenq_status: 9, nieuwsbrief: 99,
reference: nil, kadoboncode: nil, boeking_tijdcode: 1030624003,
servicemail_status: nil, factory_master_id: 1>,] ectect

Now i want to store all the values of the "ticket_fees" in a new array.

like this...

ticket_fee = ["2", "3", "1"]

How can i do this(newbie)

Thanks..remco
Billy H. (Guest)
on 2009-02-26 11:22
(Received via mailing list)
[code]
ticket_fee = []find(:all).map{|record| ticket_fee << record.ticket_fees}
[/code]

Try it:)
btw, find(:all) you can write: 'all':
Ticket.find(:all) #=> Ticket.all




On Thu, Feb 26, 2009 at 5:17 PM, Remco S. <
removed_email_address@domain.invalid> wrote:

> cabinclass: nil, type: nil, eligibility: nil, supplier: nil, heen_datum:
> like this...
>
--
TWRUG Blog:
http://blog.rubyonrails.org.tw

CFC on Rails:
http://zusocfc.blogspot.com

Only two surfaces of a box:
http://blog.pixnet.net/zusocfc
Frederick C. (Guest)
on 2009-02-26 11:43
(Received via mailing list)
On Feb 26, 9:20 am, CFC <removed_email_address@domain.invalid> wrote:
> [code]
> ticket_fee = []find(:all).map{|record| ticket_fee << record.ticket_fees}

You might as well just do

find(:all).map{|record| record.ticket_fees}

Fred
Remco S. (Guest)
on 2009-02-26 11:44
Billy H. wrote:
> [code]
> ticket_fee = []find(:all).map{|record| ticket_fee << record.ticket_fees}
> [/code]
>
> Try it:)
> btw, find(:all) you can write: 'all':
> Ticket.find(:all) #=> Ticket.all
>
>
>
>
> On Thu, Feb 26, 2009 at 5:17 PM, Remco S. <
> removed_email_address@domain.invalid> wrote:
>
>> cabinclass: nil, type: nil, eligibility: nil, supplier: nil, heen_datum:
>> like this...
>>
> --
> TWRUG Blog:
> http://blog.rubyonrails.org.tw
>
> CFC on Rails:
> http://zusocfc.blogspot.com
>
> Only two surfaces of a box:
> http://blog.pixnet.net/zusocfc

Hi

Us this
Factory_masters = Fusioncharts::FactoryMaster.find(:all)

Output:
 [#<Fusioncharts::FactoryMaster id: 1, name: "vliegtickets">,
#<Fusioncharts::FactoryMaster id: 2, name: "vliegticket">,
#<Fusioncharts::FactoryMaster id: 3, name: "vliegtickets.nl">,
#<Fusioncharts::FactoryMaster id: 4, name: "www.vliegtickets.nl">,
#<Fusioncharts::FactoryMaster id: 5, name: "vlieg tickets">,
#<Fusioncharts::FactoryMaster id: 6, name: "vliegticket.nl">,
#<Fusioncharts::FactoryMaster id: 7, name: "goedkoop vliegen">,
#<Fusioncharts::FactoryMaster id: 8, name: "vliegtickets nl ">,
#<Fusioncharts::FactoryMaster id: 9, name: "vlieg ticket">,
#<Fusioncharts::FactoryMaster id: 10, name: "vliegtarieven">,
#<Fusioncharts::FactoryMaster id: 11, name: "vliegticket">]

Then i use your suggestion, like this

name = []Fusioncharts::FactoryMaster.find(:all).map{|record| name <<
record.name

But i get no results...

What am i doing wrong?

remco
Remco S. (Guest)
on 2009-02-26 20:02
Remco S. wrote:
> Billy H. wrote:
>> [code]
>> ticket_fee = []find(:all).map{|record| ticket_fee << record.ticket_fees}
>> [/code]
>>
>> Try it:)
>> btw, find(:all) you can write: 'all':
>> Ticket.find(:all) #=> Ticket.all
>>
>>
>>
>>
>> On Thu, Feb 26, 2009 at 5:17 PM, Remco S. <
>> removed_email_address@domain.invalid> wrote:
>>
>>> cabinclass: nil, type: nil, eligibility: nil, supplier: nil, heen_datum:
>>> like this...
>>>
>> --
>> TWRUG Blog:
>> http://blog.rubyonrails.org.tw
>>
>> CFC on Rails:
>> http://zusocfc.blogspot.com
>>
>> Only two surfaces of a box:
>> http://blog.pixnet.net/zusocfc
>
> Hi
>
> Us this
> Factory_masters = Fusioncharts::FactoryMaster.find(:all)
>
> Output:
>  [#<Fusioncharts::FactoryMaster id: 1, name: "vliegtickets">,
> #<Fusioncharts::FactoryMaster id: 2, name: "vliegticket">,
> #<Fusioncharts::FactoryMaster id: 3, name: "vliegtickets.nl">,
> #<Fusioncharts::FactoryMaster id: 4, name: "www.vliegtickets.nl">,
> #<Fusioncharts::FactoryMaster id: 5, name: "vlieg tickets">,
> #<Fusioncharts::FactoryMaster id: 6, name: "vliegticket.nl">,
> #<Fusioncharts::FactoryMaster id: 7, name: "goedkoop vliegen">,
> #<Fusioncharts::FactoryMaster id: 8, name: "vliegtickets nl ">,
> #<Fusioncharts::FactoryMaster id: 9, name: "vlieg ticket">,
> #<Fusioncharts::FactoryMaster id: 10, name: "vliegtarieven">,
> #<Fusioncharts::FactoryMaster id: 11, name: "vliegticket">]
>
> Then i use your suggestion, like this
>
> name = []Fusioncharts::FactoryMaster.find(:all).map{|record| name <<
> record.name
>
> But i get no results...
>
> What am i doing wrong?
>
> remco

i just find out..the solution...pff..

factory_masters.bookings.map{|record|
record.departure_id}.inject(Hash.new(0)) {|h,x| h[x]+=1;h}

output:

["AMS" => 4, "BCN"=> 9, "BKK"=>2]

Thanks for the support!
This topic is locked and can not be replied to.