Sunday, October 14, 2018

Rails nested forms separated

1 comment

I'm after some direction in created nested forms operating in their own forms (if that makes sense). I've created some diagrams to help explain what I'm after.

I have the nested forms working fine, I'm just interested to find out if the below is possible.

I know I don't have any code to show, but any guidance or assistance would be greatly appreciated as I'm not sure where to start.

Model

class General < ApplicationRecord  belongs_to :operation  belongs_to :report end 

Form

<%= form_with(model: general, local: true) do |f| %>  <h1>General</h1>  <%= f.text_field :first_name %>  <%= f.text_field :last_name %>  <%= f.collection_select :property_id, Property.all, :id, :name %>  <%= f.collection_select :field_id, Field.all, :id, :name %>  <h1>Operations</h1>   <%= f.fields_for :operations do |o| %>   <%= o.text_field :model %>   <%= o.text_field :type %>   <%= o.collection_select :status_id, Status.all, :id, :name %>  <% end %>  <h1>Reports</h1>  <%= f.fields_for :report do |r| %>   <%= r.text_field :first_name %>   <%= r.text_field :last_name %>   <%= r.text_area :comments %>  <% end %>  <%= f.submit 'Submit' %> <% end %> 

This is my standard form using nested forms for Operations and Reports resulting is something like this:

enter image description here

I'm looking to seperate out the Operations and Reports forms and place a link available in the General show route.

enter image description here

The user will click on the Operations link and bring up the nested form to edit.

enter image description here

1 Answers

Answers 1

I'm not sure if I understand you correctly, but I guess you can hide operations and reports using CSS, add two buttons and add an event listener on each of them to display operations form and reports form on click (changing the hidden nested forms CSS).

If You Enjoyed This, Take 5 Seconds To Share It

1 comment:

  1. Aftershokz trekz titanium - Titanium Art, Tips and Tools
    Titanium Art is a T-Shirts Made titanium forging by apple watch titanium vs aluminum T-Shirts Made by T-Shirts titanium bicycle Made by T-Shirts Made by T-Shirts Made by T-Shirts Made by T-Shirts Made 강원 랜드 바카라 by T-Shirts Made ford edge titanium by T-Shirts Made

    ReplyDelete