0

我的网站允许用户上传图片。现在我希望用户能够将他们的图像分配给一个类别。

我运行了一个类别脚手架,但是如何在我的控制器的 Def New 函数中获取一个列表以填充我在图像上传表单中的选择?

4

1 回答 1

0

Try this one :

def new 
  @categories = Category.all
end

@The Mini John, you have to put this object in your form as well. If @categories object fetches multiple categories, it will show it in your form. why are you using input, you should use select directly.

<%= f.select :category, @categories, :prompt => "Select One" %>

Hope it will help. Thanks.

于 2013-07-21T09:19:01.810 回答