nested-forms

Nested Simple Form in Rails4 - has many through, save multiple records

戏子无情 提交于 2019-12-21 02:53:10
问题 I've got a standard has_many through relationship. Humans have many Orcs through a join table Interactions. The interactions is just a table and model; no controller or views. Using the simpleform gem in Rails 4, I want to make a form from the humans page, in order to select multiple orcs out of the pool of all orcs. Once submitted, I want it to create/update as many records in the interactions table, each with the human id, and as many orc ids were selected. : AKA list notation Make a form

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

萝らか妹 提交于 2019-12-19 02:39:38
问题 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=

How to access nested params

烂漫一生 提交于 2019-12-18 13:04:15
问题 I would like to get some nested params. I have an Order that has many Items and these Items each have a Type. i would like to get the type_id parameter from the controllers create method. @order = Order.new(params[:order]) @order.items.each do |f| f.item_type_id = Item_type.find_by_name(f.item_type_id).id end The reason is that i want the user to be able to create new item_types in the view. When they do that i use an AJAX call add them to the db. When they post the form i get names of the

many-to-many: has_many :through association form with data assigned to linking model create form view

旧街凉风 提交于 2019-12-18 12:44:34
问题 I'm playing with an example from Rails Guides: http://guides.rubyonrails.org/association_basics.html#the-has_many-through-association This example has the following setup for the models: class Physician < ActiveRecord::Base has_many :appointments has_many :patients, :through => :appointments end class Appointment < ActiveRecord::Base belongs_to :physician belongs_to :patient end class Patient < ActiveRecord::Base has_many :appointments has_many :physicians, :through => :appointments end I'm

Rails - Using form_for and fields_for, how do you access the sub-object while in the fields_for block?

风流意气都作罢 提交于 2019-12-17 22:33:36
问题 In my first rails app I'm trying to use form_for and fields_for to create a nested object form. So far so good, but I can't figure out how to access the sub-object while in the fields_for block. I've pre-populated a field in the sub-object with data that I want to show in the user instructions. Models Garage: has_many :cars, :dependent => :destroy accepts_nested_attributes_for :cars Car: belongs_to :garage Garage Controller def new @garage = Garage.new for i in 1..5 @garage.cars.build :stall

Rails 3.1+ Nested Forms Issue: Can't mass-assign protected attributes

冷暖自知 提交于 2019-12-17 21:18:00
问题 I have a basketball app, where a Roster has many Players, and a Player can be on multiple Rosters.(Reason for many-to-many is for a Player-Roster archive) Roster.rb class Roster < ActiveRecord::Base belongs_to :team has_many :rosterizes has_many :players, :through => :rosterizes accepts_nested_attributes_for :players attr_accessible :jersey_number, :team_id, :class_year, :players end Rosterizes.rb (poorly named I know...) class Rosterize < ActiveRecord::Base belongs_to :player belongs_to

accepts_nested_attributes_for to link to existing record, not create a new one

跟風遠走 提交于 2019-12-17 18:28:38
问题 I have the following models class Order < AR::Base has_many :products accepts_nested_attributes_for :products end class Product < AR::Base belongs_to :order has_and_belongs_to_many :stores accepts_nested_attributes_for :stores end class Store < AR::Base has_and_belongs_to_many :products end Now I have a order view where I want to update the shops for the product. The thing is that I only want to connect the products to the existing shops in my db, not create new ones. My form in the order

Nested forms in rails - accessing attribute in has_many relation

寵の児 提交于 2019-12-17 18:28:04
问题 I have a user and a profile model. One user can have many profiles. I need to access only one information from the profiles section (viz the phone number) in my user model during the user creation process. Hence I'm trying to get it done through attr_accessible . My user.rb looks like this. has_many :profiles attr_accessible :handle, :email, :password, :profile_mobile_number attr_accessor : :profile_mobile_number The problem that I'm facing is that when I try to call the getter method profile

Rails - User Input for Multiple models on a single form - How

三世轮回 提交于 2019-12-17 15:36:50
问题 This is basically a nested form question, albeit with only one field that belongs to a parent model. My data entry form collects data for a model - however I also need to collect one other a data element/value (UserID) that actually goes into a parent record that will be created with the detail record. AFAIK Rails expects each form field to map to a model and I need to create an unbound data input field that I will use separately. How can I override this default behaviour and create a'free

Rails has_many through form with checkboxes and extra field in the join model

拜拜、爱过 提交于 2019-12-17 08:51:08
问题 I'm trying to solve a pretty common (as I thought) task. There're three models: class Product < ActiveRecord::Base validates :name, presence: true has_many :categorizations has_many :categories, :through => :categorizations accepts_nested_attributes_for :categorizations end class Categorization < ActiveRecord::Base belongs_to :product belongs_to :category validates :description, presence: true # note the additional field here end class Category < ActiveRecord::Base validates :name, presence: