views:

13

answers:

1

Hi everyone,

Im about to figure out how to call a function with one member of the collection I want to thisplay in a option_groups_from_collection_for_select.

The sample is as following:

option_groups_from_collection_for_select(@categories, :children, :name, :id, :name, 3)

In my code I need to replace the :name tag with a function that calculates the right translation. When I write this function in the model there comes a error that he does not find this method name. If i put it in to the helper controller, I dont have the information of which categorie should get translated...

The manual writes about that label method:

group_label_method: The name of a method which, when called on a member of collection, returns a string to be used as the label attribute for its <optgroup> tag.

Where do I have to write this?

Thanks Markus

+1  A: 

I assume you are calling the function like this:

option_groups_from_collection_for_select(@categories, :children, my_translate_function, :id, :name, 3)

This doesn't work because "my_translate_function" is not defined.

you have to put an colon in front of the function name like this:

option_groups_from_collection_for_select(@categories, :children, :my_translate_function, :id, :name, 3)

rails will then use the send method to call "my_translate_function" on your object.

Calavera
Perfect, that was it! Thanks a lot!
Markus