-1

I have a model that stores template data and is independent with other models. I want to construct a form where I can view all the records of that model, edit them, delete them and also create a new records. Since rails form helper requires a record, is there any way to achieve my requirement or do I have to write the form manually and handle the deleted records and new records with js ?

  • Have you looked at [this questions answer](https://stackoverflow.com/questions/21850553/editing-multiple-rows-in-a-table-updating-multiple-records)? – Peter Højlund Palluth Feb 07 '18 at 17:54
  • Possible duplicate of [Editing multiple rows in a table (updating multiple records)](https://stackoverflow.com/questions/21850553/editing-multiple-rows-in-a-table-updating-multiple-records) – Peter Højlund Palluth Feb 07 '18 at 17:56

1 Answers1

0

You'll want to iterate over all our records and then render a form for each record in itself. Here is how you might do that:

# resource/index.html.erb
// all existing records
<%= render partial: "form", collection: @all_resource_records, as: :resource %>

// new record
<%= render partial: "form", locals: { resource: ResourceModel.new } %>

-

# resource/_form.erb
<%= form_for resource do |f| %>
  // ... form fields ...
  <%= f.submit %>
<% end %>
Daniel Westendorf
  • 3,375
  • 18
  • 23
  • I do not want to submit the form every time for every records I have changed. This is creating unwanted forms for every record. – Abhishek Bhatta Feb 07 '18 at 17:24