nested-forms

symfony2 multiple nested forms prototype

柔情痞子 提交于 2019-11-28 15:35:42
I want to include a collection type inside another collection type. It should look like this: Using just one collection works fine, but I need to edit the prototype of the outer form, so it renders the prototype of the inner form for each line. Any ideas how could I do that? Also what would be the best way to save EDIT: Now I am trying to render the prototype of the nested form: <ul class="characteristics-container" data-prototype="{{ form_widget(form.characteristics.vars.prototype)|e }}" data-prototype-options="{{ form_widget(form.characteristics.options.vars.prototype|e ) }}"> {# iterate

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

半世苍凉 提交于 2019-11-28 14:24:28
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 :roster attr_accessible :player_id, :roster_id end Player.rb class Player < ActiveRecord::Base has_many

Nested paperclip form with multiple images

喜夏-厌秋 提交于 2019-11-28 12:35:30
I have a one-to-many association between a Banana model and an Image model. In addition, each Banana and Image belong to a User (via a separate association because an Image and its Banana might have different Users). I would like a nested form to create Bananas as well as Images. The kicker is that I don't know how many Images to build (note the multiple attribute). The commented out bit of the form below will create the appropriate amount of Images, but won't complete the associated User reference. Is there a way to accomplish this with fields_for (so the associations are completed) as I've

Rails 4: accepts_nested_attributes_for and mass assignment

空扰寡人 提交于 2019-11-28 11:07:42
I am trying to reproduce railscast #196 in Rails 4. However, I'm experiencing some problems. In my example I try to generate a Phonebook - each Person could have multiple PhoneNumbers These are important parts of my controller: class PeopleController < ApplicationController def new @person = Person.new 3.times{ @person.phones.build } end def create @person = Person.create(person_params) @person.phones.build(params[:person][:phones]) redirect_to people_path end private def person_params params.require(:person).permit(:id, :name, phones_attributes: [ :id, :number ]) end end and this is my new

Rails 4 nested attributes not saving

别来无恙 提交于 2019-11-28 08:34:06
I cannot seem to get nested attributes to save to the database. I am using Rails 4. Here are my models : class Answer < ActiveRecord::Base belongs_to :question end class Question < ActiveRecord::Base has_many :answers belongs_to :survey accepts_nested_attributes_for :answers, allow_destroy: true end class Survey < ActiveRecord::Base has_many :questions validates_presence_of :name accepts_nested_attributes_for :questions end Here is the controller: def create @survey = Survey.new(survey_params) respond_to do |format| if @survey.save format.html { redirect_to @survey, notice: 'Survey was

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

醉酒当歌 提交于 2019-11-28 07:35:56
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 view looks like this (using Formtastic): = semantic_form_for @order do |f| = f.inputs :for => :live

Nested forms in rails - accessing attribute in has_many relation

六月ゝ 毕业季﹏ 提交于 2019-11-28 07:25:46
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_mobile_number in a method in user.rb (the method is private, though I think it doesn't matter), I'm

Rails forms for has_many through association with additional attributes?

陌路散爱 提交于 2019-11-28 05:08:46
How can I generate form fields for a has_many :through association that has additional attributes? The has_many :through relationship has an additional column called weight . Here's the migration file for the join table: create_table :users_widgets do |t| t.integer :user_id t.integer :widget_id t.integer :weight t.timestamps end The models look like this: User has_many :widgets, :through => :users_widgets, :class_name => 'Widget', :source => :widget has_many :users_widgets accepts_nested_attributes_for :widgets # not sure if this is necessary Widget has_many :users, :through => :users_widgets,

nested form triggering a 'Can't mass-assign protected attributes warning

为君一笑 提交于 2019-11-28 02:42:11
问题 I've got a multi layer nested form User->Tasks->Prerequisites and in the same form User->Tasks->Location The location form works fine, now I'm trying to specify prerequisites to the current task. The prerequisite is a task_id stored in the :completed_task field. When I submit the form, I get the following error in the output WARNING: Can't mass-assign protected attributes: prerequisite_attributes One warning for each task in the user. I've gone through all the other questions related to this,

has_many :through nested_form that can build multiple instances

北城以北 提交于 2019-11-27 23:20:19
I have the following code in my models: Class Farm < ActiveRecord::Base has_many :farm_products, :dependent => :destroy has_many :products, :through => :farm_products accepts_nested_attributes_for :farm_products end class Product < ActiveRecord::Base has_many :farm_products, :dependent => :destroy has_many :farms, :through => :farm_products end class FarmProduct < ActiveRecord::Base belongs_to :farm belongs_to :product end I have a form to create a new Farm, and I want to create farm_products along with this form. My farm_products table can not only contain foreign key fields. How can I add or