Search code examples
ruby-on-rails-3view-helpers

Rails select_collection


I have smth like this: f.collection_select with options

I need to modify the standard behaviour of that collection_select (I need to add some option there)

Where should I do that?

I don't think this code is working, but you'll understand the idea

def collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) 
  if options[:create_div] 
    return '<div>' + @template.collection_select(@object_name, method, collection, value_method, text_method, objectify_options(options), @default_options.merge(html_options)) + '</div>'
  end 
  @template.collection_select(@object_name, method, collection, value_method, text_method, objectify_options(options), @default_options.merge(html_options))
end

Solution

  • You should wrap it as a helper. You can use app/helpers/application_helper.rb