Html代码是:
Utilities: <br>
<input type="checkbox" name="amenity[utilities][]" value="Gas">Gas<br>
<input type="checkbox" name="amenity[utilities][]" value="Electricity">Electricity<br>
<input type="checkbox" name="amenity[utilities][]" value="Water">Water<br>
<input type="checkbox" name="amenity[utilities][]" value="Parking">Parking<br>
上面的html将数据存储在DB Table列中,如下所示:
---
- Gas
- Electricity
- Parking
- Water
答案 0 :(得分:1)
这是因为Rails将对象序列化为YAML以便将其存储在数据库中。你看到的实际上是一个YAML序列化数组。这里:
require 'yaml'
dbstr = "---
- Gas
- Electricity
- Parking
- Water"
# => "--- \n- Gas\n- Electricity\n- Parking\n- Water"
YAML::load dbstr
# => ["Gas", "Electricity", "Parking", "Water"]
的文档