Skip to content

Instantly share code, notes, and snippets.

@ecpplus
Created September 13, 2011 17:36
Show Gist options
  • Save ecpplus/1214451 to your computer and use it in GitHub Desktop.
Save ecpplus/1214451 to your computer and use it in GitHub Desktop.
Railsで1つのformで複数のインスタンスを処理する時
<%= form_for :users, :url => {:action => :create_multi}, :html => {:method => :post} do |f| %>
<% 0.upto(3) do |i| %>
<%= f.text_field :name, :index => i + 1 %>
<% end %>
<%= f.submit 'upload' %>
<% end %>
def create_multi
0.upto(3) do |i|
User.create!(params[:users][i.to_s])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment