开发者

Rails select_collection

开发者 https://www.devze.com 2023-04-01 11:37 出处:网络
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)

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)) + '</开发者_StackOverflowdiv>'
  end 
  @template.collection_select(@object_name, method, collection, value_method, text_method, objectify_options(options), @default_options.merge(html_options))
end


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

0

精彩评论

暂无评论...
验证码 换一张
取 消