[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Hash is not merged / recursive function

Dominik Krebs

1/5/2009 2:35:00 PM

Hi,

i'm new to ruby, but i really like it.

I'm trying to extend Ruby on Rails FormHelper with a custom function
which returns a recursive tree select field for "acts_as_tree"-models.

My Problem is, that the hash is not being merged correctly and so i only
get values which are up to the root of the tree.

Thanks for all answers.

Here's my code:

module ActionView
module Helpers
class FormBuilder
def tree_select_options(collection, value_method, text_method,
level = 0)
choices = {}
collection.map do |element|
choices[" " * level + element.send(text_method)] =
element.send(value_method)
if (element.children.size > 0)
choices.merge(tree_select_options(element.children,
value_method, text_method, level+5))
end
end
return choices
end

def tree_select(method, collection, value_method, text_method,
options = {}, html_options = {})
choices = tree_select_options(collection, value_method,
text_method)
@template.select(@object_name, method, choices,
options.merge(:object => @object), html_options)
end
end
end
end
--
Posted via http://www.ruby-....

6 Answers

Robert Dober

1/5/2009 4:21:00 PM

0

On Mon, Jan 5, 2009 at 3:35 PM, Dominik Krebs
<dominik.krebs@netzkollektiv.com> wrote:
I have no idea what's wrong with your code, but I happen to know a
Ruby Guru, so I asked him for help, here is what he told me, hopefully
that will enlighten you ;)

504/7 > irb
irb(main):001:0> options={:value => 42}
=> {:value=>42}
irb(main):002:0> options.update( :answer => 42 )
=> {:value=>42, :answer=>42}
irb(main):003:0> options
=> {:value=>42, :answer=>42}
irb(main):004:0> options.merge( :wisdom => 42 )
=> {:value=>42, :answer=>42, :wisdom=>42}
irb(main):005:0> options
=> {:value=>42, :answer=>42}
irb(main):006:0> options.merge!( :wisdom => 42 )
=> {:value=>42, :answer=>42, :wisdom=>42}
irb(main):007:0> options
=> {:value=>42, :answer=>42, :wisdom=>42}

HTH
Robert

--
It is change, continuing change, inevitable change, that is the
dominant factor in society today. No sensible decision can be made any
longer without taking into account not only the world as it is, but
the world as it will be ... ~ Isaac Asimov

Jeff

2/22/2011 1:55:00 PM

0

On Feb 21, 10:03 pm, Nil <redno...@REMOVETHIScomcast.net> wrote:
> On 21 Feb 2011, Shaw...@webtv.net (Tony) wrote in rec.music.beatles:
>
> >  I saw them in '86 during their 20th reunion tour. It was the biggest
> > tour of the year.
>
> I have a recording of The Monkees '86 tour. It's great! They were
> singing really well, especially Mickey, and they were backed by a
> crackin' band. I recently digitalized that live LP, and I've been
> listening to it a whole lot.
>
> >  I saw Mike in '70.
>
> I saw Peter Tork last year.

I believed in yesterday, yesterday.

The Arranger

2/22/2011 5:45:00 PM

0

On Feb 21, 11:03 pm, Nil <redno...@REMOVETHIScomcast.net> wrote:
> On 21 Feb 2011, Shaw...@webtv.net (Tony) wrote in rec.music.beatles:
>
> >  I saw them in '86 during their 20th reunion tour. It was the biggest
> > tour of the year.
>
> I have a recording of The Monkees '86 tour. It's great! They were
> singing really well, especially Mickey, and they were backed by a
> crackin' band. I recently digitalized that live LP, and I've been
> listening to it a whole lot.
>
> >  I saw Mike in '70.
>
> I saw Peter Tork last year.

I saw him this summer at the Topsfield (Massachusetts) Fair. My 15-
year-old daughter asked him to sing some obscure song he sang on an
album. And he held up the autograph line to sing it to her. Made her
year.

The Arranger

Donna

2/22/2011 6:31:00 PM

0

On Feb 22, 12:44 pm, The Arranger <recur...@gmail.com> wrote:
> On Feb 21, 11:03 pm, Nil <redno...@REMOVETHIScomcast.net> wrote:
>
> > On 21 Feb 2011, Shaw...@webtv.net (Tony) wrote in rec.music.beatles:
>
> > >  I saw Mike in '70.
>
> > I saw Peter Tork last year.
>
> I saw him this summer at the Topsfield (Massachusetts) Fair. My 15-
> year-old daughter asked him to sing some obscure song he sang on an
> album. And he held up the autograph line to sing it to her. Made her
> year.
>
> The Arranger

That's adorable. How nice of him.

I've seen them perform at small venues (sans Nesmith), and it's always
a great time. Once at a party, I was in the presence of Micky Dolenz,
but I didn't meet him... although there's a photo of me with him in
the background. At another time, though, I did get to speak with Davy
Jones... and had the pleasure of kissing him on the cheek. How nice
not to have to stand on my toes for it.

BTW, I like the comic on the page of that article. Sad, but true. :)

BlackMonk

2/22/2011 10:53:00 PM

0

On 2/22/2011 8:55 AM, who? wrote:
> On Feb 21, 10:03 pm, Nil<redno...@REMOVETHIScomcast.net> wrote:
>> On 21 Feb 2011, Shaw...@webtv.net (Tony) wrote in rec.music.beatles:
>>
>>> I saw them in '86 during their 20th reunion tour. It was the biggest
>>> tour of the year.
>>
>> I have a recording of The Monkees '86 tour. It's great! They were
>> singing really well, especially Mickey, and they were backed by a
>> crackin' band. I recently digitalized that live LP, and I've been
>> listening to it a whole lot.
>>
>>> I saw Mike in '70.
>>
>> I saw Peter Tork last year.
>
> I believed in yesterday, yesterday.

Does that mean that you were really believing in today at the time or
did you believe in two days ago?

hislop

2/24/2011 12:25:00 AM

0

On 22/02/2011 1:22 PM, Tony wrote:
> I saw them in '86 during their 20th reunion tour. It was the biggest
> tour of the year.
> I saw Mike in '70.
>

I saw them in early '87 in Australia. It was only 2, Peter Tork and
David Jones. Fond memories.