Populating a Select with Model Data in Rails

前端 未结 2 1119
执念已碎
执念已碎 2021-02-07 22:08

I feel the need to apologize for asking such a simplistic question, but I\'m getting increasingly frustrated with the Rails Guides. I\'m sure they answer my question, but they d

2条回答
  •  情歌与酒
    2021-02-07 22:34

    I think that select elements are one of the more confusing aspects of Rails, because as you said there seem to be a number of ways to do it.

    Try this:

    <%= f.select(:album_id, @image.albums.all.collect {|a| [a.name, a.id]}) -%>
    

提交回复
热议问题