rails collection_select vs. select

后端 未结 3 1687
隐瞒了意图╮
隐瞒了意图╮ 2021-01-31 08:44

collection_select and select Rails helpers: Which one should I use?

I can\'t see a difference in both ways. Both helpers take a collection and

3条回答
  •  梦毁少年i
    2021-01-31 09:11

    collection_select is intended to be used when the list of items is an array of ActiveRecord objects. collection_select is built on the top of select so it's a convenient method when you need to display a collection of objects and not an array of strings.

    collection_select(:post, :author_id, Author.find(:all), :id, :name)
    

提交回复
热议问题