nested-attributes

rails: create Parent, if doesn't exist, whilte creating child record

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 07:47:16
问题 Any best practices for the following?: I have Manufacturer model that has_many Inventory In my new Inventory form I want a field that maps to Manufacturer.name so that when one submits the new Inventory form the app: searches for a manufacturer with the 'name' from the form if it exists then assign the id to @inventory.manufacturer_id and save @inventory if it doesn't exist then create the manufacturer with the 'name' from the form, assign the id to @inventory.manufacturer_id and save have

Rails 3 I18n label translation for nested_attributes in has_many relationship

房东的猫 提交于 2019-12-01 07:35:34
Using: Rails 3.0.3, Ruby 1.9.2 Here's the relationship: class Person < ActiveRecord::Base has_many :contact_methods accepts_nested_attributes_for :contact_methods end class ContactMethod < ActiveRecord::Base attr_accessible :info belongs_to :person end Now when I try to customize the contact_method labels in I18n, it doesn't recognize it. en: helpers: label: person[contact_methods_attributes]: info: 'Custom label here' I have also tried: person[contact_method_attributes] This works just fine for 1-1 relationships, e.g. person[wife_attributes]: name: 'My wife' but not person[wives_attributes]

ActiveRecord::AssociationTypeMismatch when attempting to save nested attributes in Rails

↘锁芯ラ 提交于 2019-12-01 07:32:55
I read through a lot of pages on `has_one relationships and nested attributes but haven't been successful in making this work. Any help would be fantastic. Each User has_one Network. I'm trying to gather information for both attributes in one form but keep getting the exception ActiveRecord::AssociationTypeMismatch in UsersController#create The parameters passed are: {"utf8"=>"✓", "authenticity_token"=>"I54tm1ovzHEHaXbBLTT+5tqBJv2795sKg978ot3HDBc=", "user"=>{"name"=>"Bilbo Baggins", "email"=>"bilbo@lotr.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "network"=>{"home

accepts_nested_attributes_for: What am I doing wrong

 ̄綄美尐妖づ 提交于 2019-12-01 03:43:59
问题 I try do create a one-to-many connection in rails4. However, although I don't get an error, the nested attribute is not stored. What am I doing wrong? Station-Models class Station < ActiveRecord::Base has_many :adresses accepts_nested_attributes_for :adresses end Adress-Model class Adress < ActiveRecord::Base belongs_to :station end Station-Controller class StationsController < ApplicationController def new @station = Station.new @station.adresses.build end def create @station = Station.new

Rails nested attributes form for polymorphic/single table inheritance associations

我怕爱的太早我们不能终老 提交于 2019-11-30 22:24:10
I am working on a form (using SimpleForm) that allows you to edit embedded associations. The problem that I'm running into is that the nested models are subclasses so they are different types with potentially different fields. I'm creating hidden forms for each type of model, and using JavaScript to display the form for the selected type. FYI, I'm using the following gems: Rails 3.2 Mongoid SimpleForm Here's a simplified example of what I have so far: class Garage include Mongoid::Document embeds_one :vehicle accepts_nested_attributes_for :vehicle end class Vehicle include Mongoid::Document

strong parameter and json input rails 4

一曲冷凌霜 提交于 2019-11-30 20:22:40
I am trying to save data through JSON String in which I have nested associated attributes. I do not want to use attr_accessible. I almost got the logic of strong parameter but still got the problem to make them work. I am getting JSON string and using it to save data using this data = request.body.read @inputData = Person.new(JSON.parse(data)) @inputData.save! if@inputData.valid? render :status => 200, :json => "Data inserted successfully" else render :status => 404, :json => "Not Inserted " end I have defined permit strong parameter method allow nested attributes like this def referral_params

Rails 4 Not Updating Nested Attributes Via JSON

♀尐吖头ヾ 提交于 2019-11-30 17:53:09
I've scoured related questions and still have a problem updating nested attributes in rails 4 through JSON returned from my AngularJS front-end. Question: The code below outlines JSON passed from AngularJS to the Candidate model in my Rails4 app. The Candidate model has many Works, and I'm trying to update the Works model through the Candidate model. For some reason the Works model fails to update, and I'm hoping someone can point out what I'm missing. Thanks for your help. Here's the json in the AngularJS front-end for the candidate: {"id"=>"13", "nickname"=>"New Candidate", "works_attributes

Rails nested attributes form for polymorphic/single table inheritance associations

穿精又带淫゛_ 提交于 2019-11-30 17:47:52
问题 I am working on a form (using SimpleForm) that allows you to edit embedded associations. The problem that I'm running into is that the nested models are subclasses so they are different types with potentially different fields. I'm creating hidden forms for each type of model, and using JavaScript to display the form for the selected type. FYI, I'm using the following gems: Rails 3.2 Mongoid SimpleForm Here's a simplified example of what I have so far: class Garage include Mongoid::Document

Rails: Getting rid of generic “X is invalid” validation errors

江枫思渺然 提交于 2019-11-30 13:47:57
I have a sign-up form that has nested associations/attributes whatever you want to call them. My Hierarchy is this: class User < ActiveRecord::Base acts_as_authentic belongs_to :user_role, :polymorphic => true end class Customer < ActiveRecord::Base has_one :user, :as => :user_role, :dependent => :destroy accepts_nested_attributes_for :user, :allow_destroy => true validates_associated :user end class Employee < ActiveRecord::Base has_one :user, :as => :user_role, :dependent => :destroy accepts_nested_attributes_for :user, :allow_destroy => true validates_associated :user end I have some

rails ActiveAdmin nested form has_one accepts_attributes_for formtastic issue

↘锁芯ラ 提交于 2019-11-30 06:31:00
问题 I am using ActiveAdmin and Rails 3.1 -- having problem understanding whether the following is a bug, or if there is some way to do it correctly that I am not understanding. I am trying to use a nested model with a has one relationship, so that I can create a page and fill out it's meta data in 1 step. -- (page has_one meta_data, accepts_nested_attributes_for meta_data) Example 1) in this example, when I click new page, meta data section is there but there are no input fields -- also, if I