要在 form 里动态增加字段,抄袭了 http://railscasts.com/episodes/74-complex-forms-part-2 里面的内容,不知道怎么回事。想请教一下各位:
home.html.erb
1 <%= form_for @add_dev, as: 'add_dev', url: { controller: "home", action: "create" } do |f| %>
2 <%= f.label "Ip" %>
3 <%= f.text_field :ip_addr %>
4 <div id="add_dev">
5 <%= render partial: "sys", collection: @add_dev.syss %>
6 </div>
7 <%= add_dev_link "Add" %>
8 <%= f.submit "Submit" %>
9 <% end %>
_sys.html.erb
1 <%= fields_for "add_dev[syss_attributes][]", sys do |sys_stat| %>
2 <p>
3 Server: <%= sys_stat.text_field :server %>
4 Port: <%= sys_stat.text_field :port %>
5 <%= sys_stat.hidden_field :oid, value: get_oid %>
6 </p>
7 <% end %>
helper
19 def add_dev_link(name)
20 link_to_function name, nil do |page|
21 page.insert_html :bottom, partial: 'sys', object: Sys.new
22 end
23 end
运行没问题,就是点击后没反应!