【发布时间】:2012-02-02 15:53:05
【问题描述】:
我是 ruby on rails 的新手(并且 StackoverFlow 作为注册会员)
不过,我知道我可以使用 myString.split(",") 拆分字符串,例如
那不是问题。
我有什么:
另一个表单中的动态数量的嵌套表单字段,目前还可以
我想做的事:
我在每个嵌套表单中都有一个 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”。这可以让你有一个可能的关系,或者你可以尝试序列化
标签: html ruby-on-rails ruby forms nested-forms