nested-forms

nested_form, has_many :through, updating attribute on join model

强颜欢笑 提交于 2019-12-01 10:52:39
问题 I'm using ryan bates' plugin nested_form and i have been trying to write my form for a has_many :through relationship. I have 3 models: Profile has_many :memberships has_many :organizations, :through => :memberships accepts_attributes_for :organizations attr_accessible :organization_attribtues Membership has_many :profiles has_many :organizations Organization has_many :memberships has_many :profiles, :though => :memberships The below form is for the profile but with the organization nested

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

我与影子孤独终老i 提交于 2019-12-01 08:02:32
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 validations work on the new Inventory form such that, if the the Inventory form fails validation on a

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

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

How do I pass an array to fields_for in Rails?

∥☆過路亽.° 提交于 2019-12-01 05:12:07
问题 I want to use fields_for on a subset of records in an association. I have a Month model, which has_many :payments . But in my form in my view I only want to have fields_for some of those payments. For example: - fields_for @month.payments.large This doesn't work. Can I pass a set of records to fields_for , rather than the usual symbol ( fields_for :payments ) approach? 回答1: You can add additional association for large payments, for example: class Month < ActiveRecord::Base has_many :payments

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

PrimeFaces nested form inside p:dialog with appendTo=\"@(body)

偶尔善良 提交于 2019-11-30 19:47:15
I have this fragment: <h:form id="form"> <!-- other content --> <p:panel id="panel" header="test"> <p:inputText id="input1" value="#{viewScope.prop1}" required="true" /> <p:commandButton id="button1" process="@form" update="@form @widgetVar(dialog)" oncomplete="PF('dialog').show()" value="ok" /> </p:panel> <!-- other content --> </h:form> <p:dialog id="dialog" header="dialog" widgetVar="dialog" modal="true"> <h:form id="form2"> <p:inputText id="input2" value="#{viewScope.prop1}" required="true" /> <p:commandButton id="button2" process="@form" update="@form" value="ok" /> </h:form> </p:dialog>

Why do I get a AssociationTypeMismatch when creating my model object?

心已入冬 提交于 2019-11-30 18:00:26
I get the following error: ActiveRecord::AssociationTypeMismatch in ContractsController#create ExchangeRate(#2183081860) expected, got HashWithIndifferentAccess(#2159586480) Params: {"commit"=>"Create", "authenticity_token"=>"g2/Vm2pTcDGk6uRas+aTgpiQiGDY8lsc3UoL8iE+7+E=", "contract"=>{"side"=>"BUY", "currency_id"=>"488525179", "amount"=>"1000", "user_id"=>"633107804", "exchange_rate"=>{"rate"=>"1.7"}}} My relevant model is : class Contract < ActiveRecord::Base belongs_to :currency belongs_to :user has_one :exchange_rate has_many :trades accepts_nested_attributes_for :exchange_rate end class

Why do I get a AssociationTypeMismatch when creating my model object?

旧城冷巷雨未停 提交于 2019-11-30 16:48:15
问题 I get the following error: ActiveRecord::AssociationTypeMismatch in ContractsController#create ExchangeRate(#2183081860) expected, got HashWithIndifferentAccess(#2159586480) Params: {"commit"=>"Create", "authenticity_token"=>"g2/Vm2pTcDGk6uRas+aTgpiQiGDY8lsc3UoL8iE+7+E=", "contract"=>{"side"=>"BUY", "currency_id"=>"488525179", "amount"=>"1000", "user_id"=>"633107804", "exchange_rate"=>{"rate"=>"1.7"}}} My relevant model is : class Contract < ActiveRecord::Base belongs_to :currency belongs_to

Rails 3 Nested Models unknown attribute Error

。_饼干妹妹 提交于 2019-11-30 14:48:38
I have a model "Issue" and a nested Model "Relationship" In the issue.rb I have mentioned: has_many :relationships, :dependent => :destroy accepts_nested_attributes_for :relationships, :allow_destroy => true In relationship.rb I have mentioned: belongs_to :issue Following Ryan Bates Railcast#196 I have the following in my issues_controller: relationship = @issue.relationships.build However, I am encountering an error "unknown attribute: relationship" Am I doing something incorrectly here? I do see the Relationships Attributes being passed to the server in the log however, this error does not