Created
September 13, 2011 17:36
-
-
Save ecpplus/1214451 to your computer and use it in GitHub Desktop.
Railsで1つのformで複数のインスタンスを処理する時
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= 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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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