2012-06-29 55 views
1

我使用简单的表单宝石,我想知道你如何做一个collection_select?我知道你可以做一个选择,但你如何从集合中获得价值?Rails:Collection简单形式

因此,例如,你会如何在一个简单的形式做到这一点:

collection_select(:post, :author_id, Author.all, :id, :name_with_initial, :prompt => true) 

感谢

回答

5

你会做这样的:

collection_select(:post, :author, Author.all, :id, :name_with_initial) 

看看SimpleForm - Collection Select Input

+0

这是不正确的。请将您的代码调整为:'collection_select(:post,:author,Author.all,:id,:name_with_initial)' – DJTripleThreat