开发者

Creating Variable Number of one Model instances in one Form

I've been trying to configure a submit form where users can add multiple records to a database at once by adding extra fields with jQuery. (users with names and emails)

But it submits only a single row of data and ignores the rest.

Any advice would be greatly appreciated. Thanks.

<%= semantic_form_for target.users.new, :url => resource_url, :remote => true do |f| %>
  <%= f.inputs do %>
  <开发者_如何学Go;%= f.input :email%>
  <%= f.input :name%>
  <%= f.input :email, :object =>target.users.new%>#??????? - Here is problem.
<%end%>
  <%= f.buttons %>
<%end%>

target - this is parent object


If email is a field, then your users will type several email addresses into a single input field, and you don't need the :object => target.users.new bit at all. You could serialize this as an array before saving to the db - but my guess is what you are trying to do is add an email object - ie you have a User model which has_many :emails - in which case you need to use accepts_nested_attributes :email in the User model and :fields_for :email in the view

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜