假设我有一个这样的模型:
class Animal
include DataMapper::Resource
property :id, Serial
property :type, Enum[ :cat, :bat, :rabbit, :zebra]
end
假设有一条路线指向 erb 模板以添加更多动物,@animal = session[:animal]
我将如何创建动物类型列表?
...
<form>
<% @animal.type.each do |animal| %>
<select>
<option value="<%= @animal.type" %></option>
</select>
<% end %>
</form>
(显然那段代码并不能满足我的要求,但我希望它能让它更清楚一点。)