nested-forms

Models and Nested Forms

こ雲淡風輕ζ 提交于 2019-12-02 21:20:38
问题 I'm building an app that provides functionality for both consumers and businesses. In creating my models, I'm thinking of having user (consumer) and business...where each business would also have user(s), but users wouldn't necessarily belong to a business. To reduce redundancy I'd collect name, email, etc in User and specific business info (address, phone) in Business. class Business < ActiveRecord::Base belongs_to :user end class User < ActiveRecord::Base has_one :business #only if business

Nested form update action producing duplicate results

喜夏-厌秋 提交于 2019-12-02 10:49:56
问题 During the update action of a nested form, instead of updating the current nested records, it seems to create new nested records. This is what my controller looks like : class ApplicationsController < ApplicationController before_filter :set_user_and_job def new job = params[:job_id] @application = Application.build(job) end def create @application = Application.new(application_params) @application.save redirect_to root_url, :notice => "You have now applied!" end def edit @application =

Nested form update action producing duplicate results

久未见 提交于 2019-12-02 07:18:36
During the update action of a nested form, instead of updating the current nested records, it seems to create new nested records. This is what my controller looks like : class ApplicationsController < ApplicationController before_filter :set_user_and_job def new job = params[:job_id] @application = Application.build(job) end def create @application = Application.new(application_params) @application.save redirect_to root_url, :notice => "You have now applied!" end def edit @application = Application.find(params[:id]) @answers = [] @job.questions.each do |question| @application.answers.each do

using has_many through with dynamic forms rails 4

元气小坏坏 提交于 2019-12-02 04:55:58
I want to create an appointment form with dynamics forms. But I'm not getting what I'm doing wrong I'm having trouble with the partial _appointment_record_form_fields and with appointment_controller. Someone can help me fix the controller and the view? My Models: class Appointment < ActiveRecord::Base has_many :appointment_record_forms, dependent: :destroy has_many :record_forms, through: :appointment_record_forms accepts_nested_attributes_for :appointment_record_forms, allow_destroy: true end class AppointmentRecordForm < ActiveRecord::Base belongs_to :appointment belongs_to :record_form

Rails 3.2 Create Parent Model from Child View

↘锁芯ラ 提交于 2019-12-02 04:22:23
问题 I'm having a difficult time understanding how to do this. I have two models, a project, and a course. #project.rb belongs_to :course attr_accessible :course_id, :course accepts_nested_attributes_for :course, reject_if: lambda { |a| a[:course_id] == 0 } #course.rb has_many :projects On the Projects#new page (child object), I want to type in the name of a new course and have it create the parent object. Here's my attempt in the view, but it doesn't seem to be working correctly. = form_for [

No errors and no output for rails cocoon gem

喜夏-厌秋 提交于 2019-12-02 02:18:36
I am working on a dynamically nested form using the cocoon gem. I have two models class CrossTable < ActiveRecord::Base attr_accessible :title, :table_name, :database, :folder_label_id, :foreign_fields_attributes belongs_to :folder_label has_many :foreign_fields accepts_nested_attributes_for :foreign_fields validates :title, :table_name, :database, :folder_label_id, presence: true end class ForeignField < ActiveRecord::Base attr_accessible :cross_table_id, :column_name, :description belongs_to :cross_table has_many :filter_sets end I have cocoon and jquery-rails in the gemfile I added //

remove_fields & add field link not working on nested form in rails 3.0.9

独自空忆成欢 提交于 2019-12-01 21:07:10
I am following Ryan bates neted_forms episode 1 & 2 from rails casts, I have already implemented the nested-forms functionality in one of my project before & it's working fine without any error, But in my new project I am using the same reference from rails casts but remove & add field is not working. Here is my model has_many :contacts, :dependent => :destroy accepts_nested_attributes_for :contacts, :reject_if => lambda { |a| a[:contact_name].blank? }, :allow_destroy => true The form on which I am using add field link <div class="TabbedPanelsContent"> <%= f.fields_for :contacts do |builder| %

Rails nested form error, child must exist

风流意气都作罢 提交于 2019-12-01 17:30:58
I'm following the tutorial: http://www.amooma.de/screencasts/2015-01-22-nested_forms-rails-4.2/ I'm usign Rails 5.0.0.1 But when I register a hotel, it appears that the hotel category must exist. 1 error prohibited this hotel from being saved: Categories hotel must exist My Hotel model: class Hotel < ApplicationRecord has_many :categories, dependent: :destroy validates :name, presence: true accepts_nested_attributes_for :categories, reject_if: proc { |attributes| attributes['name'].blank? }, allow_destroy: true end My Category model: class Category < ApplicationRecord belongs_to :hotel

Rails nested form error, child must exist

柔情痞子 提交于 2019-12-01 15:45:52
问题 I'm following the tutorial: http://www.amooma.de/screencasts/2015-01-22-nested_forms-rails-4.2/ I'm usign Rails 5.0.0.1 But when I register a hotel, it appears that the hotel category must exist. 1 error prohibited this hotel from being saved: Categories hotel must exist My Hotel model: class Hotel < ApplicationRecord has_many :categories, dependent: :destroy validates :name, presence: true accepts_nested_attributes_for :categories, reject_if: proc { |attributes| attributes['name'].blank? },

Rails nested form with multiple entries

谁说我不能喝 提交于 2019-12-01 14:45:25
I have a Sezzion model: attr_accessible :description has_many :session_instructors, :dependent => :destroy has_many :instructors, :through => :session_instructors accepts_nested_attributes_for :session_instructors accepts_nested_attributes_for :instructors Instructor model: attr_accessible :bio has_many :sezzions, :through => :session_instructors has_many :session_instructors, :dependent => :destroy SessionInstructor model: attr_accessible :instructor_id, :sezzion_id belongs_to :sezzion belongs_to :instructor Lastly, User model: has_many :sezzions has_many :instructors I'm trying to create a