Sean Magyar
Sean Magyar

Reputation: 2380

rails with most nested models and cocoon gem;

I have a rails4 app with nested model form. There is a product model that has_many product_features, has_many product_usecases and has_many product_competitors.

Everything works fine except when I load the page only the first nested model (product_features) will be visible. How can I also make one row visible for the other 2 models on page load?

UPDATE:

I have no js code yet for the form.

_form.html.erb

<div class="well product-well">
  <div class="row">
    <div class="col-md-12">
      <%= f.fields_for :product_features do |product_feature| %>
        <%= render 'product_feature_fields', f: product_feature %>
      <% end %>
    </div>
  </div>
    <div class="form-group">
    <%= link_to_add_association 'Add a new feature', f, :product_features %>
  </div>
</div>

<div class="well product-well">
  <div class="row">
    <div class="col-md-12">
      <%= f.fields_for :product_usecases do |product_usecase| %>
        <%= render 'product_usecase_fields', f: product_usecase %>
      <% end %>
    </div>
  </div>
  <div class="form-group">
    <%= link_to_add_association 'Add a new usecase', f, :product_usecases %>
  </div>
</div>

<div class="well product-well">
  <div class="row">
    <div class="col-md-12">
      <%= f.fields_for :product_competitions do |product_competition| %>
        <%= render 'product_competition_fields', f: product_competititon %>
      <% end %>
    </div>
  </div>
  <div class="form-group">
    <%= link_to_add_association 'Add a new competition', f, :product_competitions %>
  </div>
</div>

enter image description here

Upvotes: 0

Views: 60

Answers (1)

Sean Magyar
Sean Magyar

Reputation: 2380

It was a weird validation problem. I used to have product.usecase attribute then decided to change it to product_usecase model and forgot to take out the validation (product.usecase must be present) from the product model.

Upvotes: 1

Related Questions