nested-forms

Rails: How to have a nested form save to different nested models?

别来无恙 提交于 2019-12-14 02:43:17
问题 Context: I have a Company model that has many projects . Each project has many tasks . The company has many employees . Employee belongs to Company and has many tasks . It is one employee per task and an employee will have only one task per project . Schema: Problem: I'm building a form to create a project where the user can add multiple tasks . Each task has an amount of hours specified and the employee performing the task . Upon submission the form should create a single project record, one

Nested dynamic array forms in Angular Reactive forms

心已入冬 提交于 2019-12-13 17:43:48
问题 I'm having a array form namely "address" and this will be a dynamic once the user clicks the "Add Address" button immediately one address form will add. I implemented this with an issue (Add/Remove address works fine). Now I need to add a dynamic contact numbers similar like address. A address may contain one or more than one phone numbers, if the user clicks "Add Phone number" need to add a new phone number form inside the address form, the functionality will required in all the address

Nested Form complex has_many :through

跟風遠走 提交于 2019-12-13 17:23:24
问题 I have a complex has_many through relationship, where Users can apply to Jobs through Applications. When creating each job, the admin chooses certain questions. During Applications#new, when the user is applying to a new job, I'd also like the user to answer the questions in order to apply. To do this, I set up my models like so: Job has many users through application has many questions Users has_many jobs through application Application belongs_to :user belongs_to :job has_many :answers

Rails Nested Forms Attributes not saving if Fields Added with jQuery

大憨熊 提交于 2019-12-13 11:37:58
问题 I have a rails form with a nested form. I used Ryan Bates nested form with jquery tutorial and I have it working fine as far as adding the new fields dynamically. But when I go to submit the form it does not save any of the associated attributes. However if the partial builds when the form loads it creates the attribute just fine. I can not figure out what is not being passed in the javascript that is failing to communicate that the form object needs to be saved. Any help would be great.

params.require().permit does not work as expected

不问归期 提交于 2019-12-13 08:14:18
问题 I have this controller class PeopleController < ApplicationController def new @person = Person.new @person.phones.new end # this is the action that gets called by the form def create render text: person_params.inspect # @person = Person.new(person_params) # @person.save # redirect_to people_path end def index @person = Person.all end private def person_params params.require(:person).permit(:name, phones_attributes: [ :id, :phone_number ]) end end and this view <%= form_for :person, url:

nested_form not saving to model Rails 3

和自甴很熟 提交于 2019-12-13 07:24:11
问题 I think I am on the right path for the following, though i cannot save the form data to the model. I have 2 models class Prediction < ActiveRecord::Base attr_accessible :home_team, :away_team, :home_score, :away_score, :fixtures_attributes has_many :fixtures accepts_nested_attributes_for :fixtures end class Fixture < ActiveRecord::Base attr_accessible :home_team, :away_team, :fixture_date, :kickoff_time belongs_to :predictions end To create a new prediction record i have a form that takes all

Rails 4: child record ID is saved but not its attributes, using nested form with has_many through relationship

笑着哭i 提交于 2019-12-13 06:53:48
问题 I have 3 models with a has_many through relationship: Food (eg: Chocolate), Sub (Chocolate food substitute), Joint (joint table). Say @food = Food.find(1); The has_many through relationship allows me to do @subs = @food.subs which return all substitutes associated with @food. This work fine, however only the Sub id is saved and not its attributes which are :name and :description as you can see it returned nil when trying to save @food.subs in my create action in my controller: => #

rails nested form changes id to decimal

家住魔仙堡 提交于 2019-12-13 06:06:37
问题 Quick problem description The value of the id in a nested form is rendered as 10006.0 instead of 10006 (decimal/float instead of an integer) resulting in an ActiveRecord::RecordNotFound exception. What is causing this behaviour?? The code setup So I followed the rails-guides tutorial on how to build nested forms. My 2 models are: class Broker < ActiveRecord::Base has_many :execution_groups, dependent: :destroy accepts_nested_attributes_for :execution_groups, allow_destroy: true, reject_if:

Nested form in Active Admin

青春壹個敷衍的年華 提交于 2019-12-13 05:21:01
问题 I need help! I have 2 models for a Survey: class Poll < ActiveRecord::Base has_many :poll_questions, :dependent => :destroy accepts_nested_attributes_for :poll_questions, :reject_if => lambda { |a| a[:text].blank? }, :allow_destroy => true end There is model for questions as follows: (it seems these assocciations are correct) class PollQuestion < ActiveRecord::Base belongs_to :poll has_many :poll_answers, :dependent => :destroy accepts_nested_attributes_for :poll_answers, :reject_if => lambda

Cannot save record to database RAILS nested forms

假如想象 提交于 2019-12-13 05:19:29
问题 I cannot seem to save my record with nested forms. This is what pry says: pry(#<VenuesController>)> @venue.save (0.3ms) begin transaction Tag Exists (0.2ms) SELECT 1 AS one FROM "tags" WHERE ("tags"."name" = 'All ' AND "tags"."id" != 2) LIMIT 1 Tag Exists (0.1ms) SELECT 1 AS one FROM "tags" WHERE "tags"."name" = '' LIMIT 1 (0.1ms) rollback transaction => false I thought I followed everything correctly. This is my nested form for tags Tags: <%= f.collection_check_boxes :tag_ids, Tag.all, :id,