Following is an extract from API for collection_select method:
collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {})
My collection is the array of strings. In the text_method I would like to output the modified string gsub(some regex stuff). What is the best way of doing it? I could think of reopening String class and implementing something for text_method but if would imagine its not really nice way.
Thanks.
There are three options what you could do:
myapp_gsub(without arguments) and include that astext_method.ActionView::Helpers::FormOptionsHelper#options_from_collection_for_selectand add the option that thetext_methodcan be a block. Then you are free to define the text_method as well as block. I would not recommend that if you are not completely sure what the impact of that “enhancement” is.So opening the
Stringclass would be the easiest option, in my opinion.