Home > javascript > rails with most nested models and cocoon gem;

rails with most nested models and cocoon gem;

February 16Hits:14
Advertisement

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> 

rails with most nested models and cocoon gem;

Answers

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.

Related Articles

  • rails with most nested models and cocoon gem;

    rails with most nested models and cocoon gem;February 16

    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_fe

  • Rails routes for self nested modelsJanuary 15

    In my rails app I have a Task model. In my app, my tasks can have substasks and so on. Since my subtasks are tasks with only a parent task, I did a self-nested model such as class Task < ActiveRecord::Base ## Self Join has_many :subtasks, class_name:

  • Wicked Gem with cocoon gem and devise user modelFebruary 8

    So I have a User model generated with devise, and I am using Wicked gem to give me multiform option on taking more data from the user and storing it in the user model. Everything is working fine but know I'm trying to add another model where user has

  • Rails - Why does my nested model form not require 'accepts_nested_attributes_for'February 9

    I have two models item and user_item. Item has many user_items and user_items belongs to item. I have a form where a user can create a new item. In the form a user should include a picture. The name, description, and tags get saved to a new item obje

  • Rails nested models and virtual attribute initializationJanuary 27

    I have a problem understanding how are attributes "sent" to nested model(s), and if is possible to do this for model with virtual attrubute too. I have three models: class User < ActiveRecord::Base ... has_and_belongs_to_many :clearancegoods

  • Render only One Row in link_to_add_association using cocoon gemJanuary 16

    I have HomeBannerSlider model which has has_many relation wih Image. I used the cocoon gem to add multiple association to render images i used following code in y form = f.simple_fields_for :images do |image| = render 'image_fields', f: image .links

  • Creating Instance of Nested model inside parent controllerJanuary 18

    I would like to know if it is possible to create an instance of a nested model inside the parents controller. Let me explain. I have a model called Museum and another model called Museumimage. Museumimage has only one field which is an attachment, ma

  • Nested Iteration with model builder - using nested models

    Nested Iteration with model builder - using nested modelsSeptember 7

    I'm new to using model builder and have to do a nested iteration (for every month I have to iterate through 6 parameters). I am thinking of doing that by using nested models. One model doing the interation through monthes and then providing the curre

  • PHP MVC class with controller and nested model

    PHP MVC class with controller and nested modelNovember 26

    I had asked a first question about this class a while ago and got a few answers here which made me rewrite it completely. I removed all statics and globals, added my variables as arguments for the constructor, and pass them again as reference through

  • Problem validating parent model with nested models in modelbuilder

    Problem validating parent model with nested models in modelbuilderMarch 24

    I have a parent model with several nested models. I'm having trouble getting the parent model to validate. The issue is with sub model 4. The two screenshots are of the parent model and sub model 4. The output from sub model 3 feeds into parameter "M

  • Using global parameters in nested models of ModelBuilder?October 22

    I have a model that consists of two nested models and various parameters. There are two parameters that are common to all of the models (including the overall "grand" model). The common parameters are in-line variables and serve to assign unique

  • Knockout JS Mapping fromJS nested modelsJanuary 27

    I am having trouble understanding how to work with Knockout JS Mapping Plugin. I have some nested models (as seen below) and what I am currently doing is just using the ko.mapping.fromJS() in the parent model. What I am noticing is that computed valu

  • Trying to update nested model first on before_saveFebruary 11

    I am calculating :price in my nested item model in order to map it in my invoice model. The problem is that the before_save in the invoice model is being called first and I want it to be called after the before_save in the nesteditem model Any ideas

  • Before validation on nested modelJanuary 9

    I have a nested model items and I am trying to multiply two columns together cost and quantity to set the last column price. I need to set the column price before the form is saved and i need to also validate the model. The before_validation call bac

  • Rails: nested models disappearing after validationJanuary 26

    I have a model: class Invoice < ActiveRecord::Base belongs_to :case has_many :invoice_positions accepts_nested_attributes_for :invoice_positions, allow_destroy: true And i have a form createn with https://github.com/nathanvda/cocoon but i have one sm

  • What's the rails way of nesting routes with shared models?January 29

    I have following models: board.rb task.rb comment.rb Board has many comments, comment belongs to board. Task has many comments, comment belong to task. Board has many tasks, task belongs to board. What is the cleanest way of handling the routes? It c

  • Creating nested models in Rails 4 forum appJanuary 31

    Hello I am making a Forum application in Rails 4. It can have numerous forums, each with numerous topics. Each topic can have many posts. When creating a new topic, one must also create the initial post, much like Stack Overflow itself. Therefore, I

  • Rails how to create select dropdown with double nested model?January 19

    I'm new to Rails and I'm trying to create a select dropdown for menu items. The complicated part is each Restaurant has many Categories which have many menu items. My goal is to have a dropdown that prints something like the following: <optgroup labe

  • form validation with nested models in Rails

    form validation with nested models in RailsJanuary 22

    I have this problem. I need to validate the attributes of two models in the same form in Rails. One is the parent of the other. The form is like this: <%= semantic_form_for @professional do |pro| %> <%= pro.inputs :id => "information"

  • Ruby on rails. Form for a nested model in a different viewFebruary 13

    I've been battling this for a while now and I can't figure it out. I have a user model using devise. Users can upload songs, and add youtube videos etc.. I'm trying to let users add/delete songs and videos from the devise edit registrations view. Vid

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.577 s.