FAQ Database Discussion Community


nested form, empty symbol for has_many relationship

ruby-on-rails-3.2,nested-forms
So, after I have migrated our application from rails 2 to 3.2, I’ve implemented a nested form for a new class, which has worked perfectly. Unfortunately, I cannot get the same to work with a migrated class and it's keeping me on the edge for days now. Parent model: class...

Facing issue in edit-update action in nested form in rails4?

ruby-on-rails,ruby-on-rails-4,nested-forms
Hi I am using gem "nested_form" and included has_many association in my app sample code is : class Question < ActiveRecord::Base has_many :choices accepts_nested_attributes_for :choices end and in my controller have included this : class QuestionsController < ApplicationController before_action :set_questions, only: [:edit, :update] def edit end def update if @question.update_attributes(question_params)...

Creating a object with nested form rails

ruby,ruby-on-rails-3,ruby-on-rails-4,nested-forms
I have 3 tables: members, meetings, meeting_has_members. The models are: member.rb class Member < ActiveRecord::Base has_many :meeting_has_members has_many :meetings, through: :meeting_has_members accepts_nested_attributes_for :meeting_has_members accepts_nested_attributes_for :meetings meeting.rb class Meeting < ActiveRecord::Base has_many :meeting_has_members has_many :members, through: :meeting_has_members accepts_nested_attributes_for :meeting_has_members accepts_nested_attributes_for :members meeting_has_member.rb class...

How to create a simple nested signup form?

ruby-on-rails,ruby,ruby-on-rails-4,nested-forms,nested-attributes
I'm really stuck. Is there anyone who could help? What am I doing wrong? How can I create a simple nested form? I have two models each with their own resources: Organizations and Members. An organization has multiple members and a member is only a member to one organization. How...

Rails simple_form - Nested Form NoMethodError in “show” page

ruby-on-rails,simple-form,nested-forms
Im having some difficulty with making a nested form to work using simple_form, specifically with the show page. I have a Profile and Experience model, and would like to nest the Experience model within the Profile model. I believe I have set up the form file and controller and associations...

Behaviour of assign_attributes with nested forms

ruby-on-rails,variable-assignment,nested-forms
assign_attributes doesn't seem to recognise when I delete nested objects. I have a model called Order: class Order < ActiveRecord::Base has_many :deliveries, :dependent => :destroy accepts_nested_attributes_for :deliveries, :allow_destroy => true end Say I create an order with two deliveries. Then I open the 'edit order' form (which is a nested...

How to show nested form validation errors after the validation errors for the parent model?

ruby-on-rails,ruby-on-rails-4,nested-forms
Using Ruby on Rails 4.2, I have a nested form. When testing the validations for the entire form, I noticed that the validation errors for the nested form appear at the top of the validation errors list, with the validation errors for the main form appearing below. This is the...

Nested_attributes dont appear in my params

ruby-on-rails,ruby,forms,nested-forms,params
I try to include nested_form in one on my model new form. <%= form_for :master_box, url: master_boxes_path do |f| %> <%= f.label :number %><br> <%= f.text_field :number %> <%= f.fields_for :orders do |o| %> <fieldset> <%= o.label :number, "Number" %> <%= o.text_field :number %> </fieldset> <% end %> <br> <%=...

Is there a way to get the `id` of a nested_form field helper element?

ruby-on-rails,nested-forms
I am trying to create the for attribute for a label in a nested form (Using nested_form). Is there a way to get the id of a corresponding f.checkbox? HAML: = label_tag '???', "Set as On", class: primary_btn = f.check_box :is_on Additional Information: The current Model structure is like Post...

Two nested form objects

ruby-on-rails,ruby-on-rails-4,nested,nested-forms,nested-attributes
I have two nested objects (Attachment inside Widget, Widget inside Lesson). Lesson > Widgets > Attachments Lesson > Widgets > Links Everything is fine, but if I click on "Remove attachment", and then I click on "Update Lesson", nested attachments in the widget are not removed. Is that because I...

No onclick event for jQuery element added after initial page load

jquery,ruby-on-rails,nested-forms
In our rails app, we have a table where each tbody row is a nested field. I want to limit nested fields based on current field count. To do so, I am following this guide provided by the nested_form docs. To better suit our app, I modified the code below....

Nested form in a table, not working

javascript,ruby-on-rails,ruby-on-rails-4,nested-forms,fields-for
Can someone help me on how I will put my nested form in a table? my code: #app/view/master_templates/edit.html.erb <%= form_for(@master_template) do |f| %> <%= f.label :name %><br /> <%= f.text_field :name %> <table border="1"> <%= f.fields_for :master_template_details, :wrapper => false do |p| %> <%= render 'master_template_detail_fields', {f: p} %> <%...

Model-independent Rails 4 file upload in dynamically loaded (nested) form field

ruby-on-rails,file-upload,nested-forms,nested-attributes,form-helpers
I'm looking for a way for simple image upload onto the file system so that the image is not stored in the database. I understand this step is rather easy, just using a file_input tag, however I have problems making it happen because of how my form is built. I...

Add Extra Field_for in Nested form with Rails 4

javascript,ruby-on-rails,ruby-on-rails-4,coffeescript,nested-forms
I made form where I can make new Entity with all its data, and add new Users that are associated with that Entity using Has_many :through association. Here is the problem. I want to be able to add extra User field li element with button "Add extra user". I can't...

Uninitialized constant using nested forms in Rails

ruby-on-rails-4,nested-forms,uninitialized-constant
I keep getting an error saying uninitialized constant Page::PageAttachment when trying to create a nested form using the nested_form gem. Here is some relevant code. Let me know if you need any other code or have any questions. Stacktrace isn't really telling me anything except that the failing line is...

Nested form: shouldn't save if no information for child is entered

ruby-on-rails,ruby,ruby-on-rails-4,testing,nested-forms
I have a nested form to sign up a new organization and 1 member (1:many relationship between organization and its members). Both have validations in the model file and the migration file. The issue: I would like the form not to sign up anything (not organization nor member) if not...

ActiveAdmin Nested Form multiple select

ruby-on-rails-4,activeadmin,nested-forms
I'm trying to get the product_suppliers to update via the product form. The form displays all suppliers in the supplier table but it doesn't update the join table. Not sure where the error lies. Index and show show correct details but edit is not updating the join table. Starting to...

Rails 4: collection_check_box error

ruby-on-rails,ruby,forms,nested-forms,actionview
I am building a form that launches a new Campaign. With this Campaign, you can choose a Zip file and/or some PDF files. Zip and PDF files are all stored in an Uploads table. So far, it appears I can choose a Zip file, however, once I add the collection_check_box...

ActiveAdmin Papperclip Show multiple images in Index and show

ruby-on-rails-4,paperclip,activeadmin,nested-forms
Hi just a quick Question on showing multiple images on the index-page and show page. My images are stored fine in a product_images table with a product_id as the foreign key. Just going around in circles now on this. I've tried to play with similar code to no avail. row...

Create two interdependent models from one form in rails

ruby-on-rails,ruby,forms,nested-forms,nested-attributes
I have used a combination of answers from 21222015, 17572279, 2663141, and RailsGuide to try and get multiple interdependent models to be created from a form. In my application Users are used for authentication and Clinicians and Patients are models for the two different types of Users. Clinicians and Patients...

Rails Deep Nested Form with Photos

ruby-on-rails,ruby-on-rails-4,nested-forms
I have a deep nested form with offering having a gallery which has photos. offering.rb has_one :gallery, foreign_key: "offering_id",:inverse_of => :offering, dependent: :destroy accepts_nested_attributes_for :gallery, allow_destroy: true gallery.rb belongs_to :offering, foreign_key: "offering_id",:inverse_of => :gallery has_many :photos, foreign_key: :gallery_id, dependent: :destroy, inverse_of: :gallery accepts_nested_attributes_for :photos, allow_destroy: true, reject_if: proc { |attributes|...

Nested form in Play! Scala 2.2

scala,nested-forms,playframework-2.2
I have read several times the documentation but I still have problems with my nested form in Play! Scala 2.2 (detailed further). Here is my form : <form method="post" action="/admin/test2"> first name : <input type="text" name="firstname"> <br> info 0 : <input type="text" name="label[0]"> <br> info 1 : <input type="text" name="label[1]">...

Using Javascript to change target div id in link_to

javascript,ruby-on-rails,nested-forms
So I'm using Rails and nested_form, and I have the following link_to_add code: <%= f.link_to_add :exptypes, id:"addTab", :data => { :target => "#exptype_new_3" } do %> <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add an Experimental Type <script> $('#addTab').click(function() { add_tab('exptype'); }) </script> <% end %> The page source looks like this: <li...

How to declare objects for nested form in rails 4

ruby-on-rails,ruby-on-rails-4,nested-forms,has-one
I'm approaching my 2nd week of using rails, and have almost gotten the structure of my app complete (I think/hope). I'm building a staff website for a charity, which as part of their work collects and wipes computers (before sending them to African schools!). I've set up my app to...

Creating associated has_many :through records with nested forms

ruby-on-rails,nested-forms,has-many-through
Here are the models in my many-to-many relationship: class Student < ActiveRecord::Base has_many :classroom_memberships, :dependent => :destroy has_many :classrooms, :through => :classroom_memberships end class ClassroomMembership < ActiveRecord::Base belongs_to :classroom belongs_to :student end class Classroom < ActiveRecord::Base has_many :classroom_memberships has_many :students, :through => :classroom_memberships end When creating a new student, I...

Multi nested attributes with ActiveAdmin

ruby-on-rails,activeadmin,nested-forms,nested-attributes
Hey so I have three models: DataSet BrowseOption BrowseOptionData Similar to Ryan's railscasts (http://railscasts.com/episodes/196-nested-model-form-revised?view=comments) I want to have a double nested form except in ActiveAdmin. Here is my Active Admin form: form do |f| f.inputs "Data Set Info" do f.input :name f.input :display_name f.input :description f.input :cover_photo, :label => "Cover...

Nested Comment body not being saved Ruby on Rails

ruby-on-rails,devise,nested-forms,nested-attributes
I'm banging my head on my desk trying to figure out why the comment is posting comment.body, but when I go into IRB body=nil and it won't display on App show page. The structure: Apps have many comments on their show page, along with a comment form. Apps View: <h3>Comments</h3>...

Facing issue in f.link_to_add in gem “nested_form”

jquery,ruby-on-rails,ruby-on-rails-4,nested-forms
Hi I am using gem "nested_form" and in my view I have given like this <%= f.fields_for :tasks do |task_form| %> <%= task_form.text_field :name %> <div class="star-rating" ></div> <%= task_form.text_field :rate %> <% end %> <p><%= f.link_to_add "Add a task", :tasks %></p> In js file I have I have given...

When updating a nested form, how do I do something with new records?

ruby-on-rails,ruby,nested-forms,rolify
class Photo < ActiveRecord::Base has_many :item_photos has_many :items, through: :item_photos end class Item < ActiveRecord::Base has_many :item_photos has_many :photos, through: :item_photos accepts_nested_attributes_for :photos end class ItemPhotos < ActiveRecord::Base belongs_to :photo belongs_to :item end When I edit or create an Item, I also upload or remove Photos. However, more than one...