我是Ruby on Rails(和StackoverFlow作为注册会员)的新手 虽然,我知道我可以将Strings与myString.split(",")
分开。 那不是问题。Ruby on Rails窗体:我如何拆分一个字符串并将其保存为一个数组?
我有什么:
嵌套表单字段的另一种形式的动态数量,这工作好,到目前为止
我想要做什么:
我有一个textarea每个嵌套表单。 用户应输入几个单词,由","
分隔,这些单词应该保存为Array,
,所以我可以通过以后的@sector.climbing_routes
(作为一个数组)来调用它们。
现在“climbing_routes”只是一个很长的字符串。
我该如何处理这个问题?
下面是一些代码:
_sector_fields.html.erb (Nested Fields):
<div class="sector">
Sektor:
<table>
<tr>
<th><%= f.label :name %></th><th><%= f.label :description %></th><th><%= f.label :climbing_routes %></th>
</tr>
<tr>
<th><%= f.text_field :name %></th>
<th rowspan="5"><%= f.text_area :description, :rows => 5 %></th>
<th rowspan="5" ><%= f.text_area :climbing_routes , :rows => 6%></th>
</tr>
<tr>
<th>Bild 1</th>
</tr>
<tr>
<th><%= f.file_field :topo %></th>
</tr>
<tr>
<th>Bild 2</th>
</tr>
<tr>
<th><%= f.file_field :topo2 %></th>
</tr>
</table>
</div>
架构部门:
你可以做的是简单地将它们存储为逗号分隔的列表create_table "sectors", :force => true do |t|
t.string "name"
t.string "topo"
t.string "topo2"
t.string "description"
t.integer "climbing_area_id"
t.datetime "created_at"
t.datetime "updated_at"
t.string "climbing_routes"
end
可能是你可以尝试归列“climbing_routes”。这可以让你有一个可能关系或您可以尝试系列化 – PriteshJ 2012-01-04 19:18:33