I have a model named Book
, and I want to adjust the standard Book#new
to show the fields for 10 books, so that 10 can be created at once instead of just one.
I looked at this question and found that I could repeat the form if I added 10.times
to my form. However, I didn't do it correctly because a new record is saved, but with all fields null.
What I want to do is to:
- Allow the user to enter up to 10 books at one-time and then save them
- If the user populates only three book records, create only three (and ignore the seven records in the form others with null values)
My view:
<%= simple_form_for(@book) do |f| %>
<%= f.error_notification %>
<% 10.times do |index|%>
<%= f.input :title %>
<%= f.association :book_category %>
<% end %>
<%= f.submit %>
<% end %>
My controller is unchanged from the scaffolding code:
def new
@book = Book.new
end
def create
@book = Book.new(params[:book])
end