nested-forms

Rails: Use same partial for creating and editing nested items

我的梦境 提交于 2019-12-25 04:14:52
问题 I followed the Getting Started With Rails tutorial to set up a simple blog with comments. I went to apply it to my own scenario: histories with history items. Everything was more or less fine until I realized that I needed to have the ability to edit these history items (kind of like editing comments). I've got it so there's an "Edit Item" link on the partial that displays the history items. It seems to hit the edit action in the history items controller. But I get a form with blank fields

`accepts_nested_attributes_for`, but only modify the first child

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-25 03:53:17
问题 A Brief Background I'm making a conventional forum to learn/practice Rails. User Model has_many :topics has_many :posts Topic Model has_many :posts belongs_to :user Post Model belongs_to :user belongs_to :topic However, when a User is creating a new Topic, I also want them to simultaneously create the first Post within that topic (just like forums work). Additionally, when the Topic creator edits the Topic, he also edits the first Post. So, I added accepts_nested_attributes_for :posts to the

accepts_nested_attributes_for not saving the child attribute to the database

我与影子孤独终老i 提交于 2019-12-25 03:50:37
问题 My accepts_nested_attributes_for only saves the parent and not the child (nested) attributes. This is many_to_many relationship between parent and child. Problem: nothing happens and nothing is saved. But on the page, I get this message: utf8: "\xE2\x9C\x93" authenticity_token: 9Pjxt7e5RRgWVGafRyMoDqBSqmtj/R2zBSiVxGGxFOI= parent: !map:ActiveSupport::HashWithIndifferentAccess name: "Test" gender: Male children_attributes: !map:ActiveSupport::HashWithIndifferentAccess "0": !map:ActiveSupport:

Nested form in Play! Scala 2.2

不羁的心 提交于 2019-12-25 01:55:43
问题 I have read several times the documentation but I still have problems with my nested form in Play! Scala 2.2 (detailed further). Here is my form : <form method="post" action="/admin/test2"> first name : <input type="text" name="firstname"> <br> info 0 : <input type="text" name="label[0]"> <br> info 1 : <input type="text" name="label[1]"> <br> <input type="submit" value="test nested form" /> </form> And the case classes corresponding : case class Contact(firstname: String, informations: Seq

Multi-model nested form, can't add users to current account

北战南征 提交于 2019-12-25 01:35:31
问题 I've searched everywhere for a solution but haven't come up with any. The part that works : My app allows customers to create an account using a nested form. The data collected creates records in four models - accounts, users, accounts_users (because a user can be associated with many accounts), and profile (to store the user's fname, lname, phone, etc). That part that doesn't work : Once logged in, I want the users to be able to add more users to their account using the form below. I don't

How do I update a nested resource without passing the data via a form

拟墨画扇 提交于 2019-12-25 01:18:59
问题 Models class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable has_many :roles, :dependent => :destroy, :inverse_of => :user has_many :companies, :through => :roles accepts_nested_attributes_for :roles, :limit => 1, :allow_destroy => true end class Role < ActiveRecord::Base belongs_to :user, :inverse_of => :roles belongs_to :company, :inverse_of => :roles accepts_nested_attributes_for :company end class Company <

How to add multiple nested attributes to a multi file upload

寵の児 提交于 2019-12-24 18:43:53
问题 I am trying to set up a multi image upload with carrierwave. I am following the question Rails 4 multiple image or file upload using carrierwave and in particular the answer by @prograils https://stackoverflow.com/a/38769726/4779531. I have an album.rb model and a diapo.rb model. class Album < ApplicationRecord has_many :diapos accepts_nested_attributes_for :diapos, allow_destroy: true end + class Diapo < ApplicationRecord belongs_to :album has_and_belongs_to_many :authors, :join_table =>

How to use nested attributes with belongs_to association on new action?

一笑奈何 提交于 2019-12-24 17:55:55
问题 On the update action the following nested_form works, but on create I get this error: Couldn't find Student with ID=12 for Cv with ID= Controller: def new @cv = Cv.new @cv.student = current_student end def create @cv = Cv.new(params[:cv]) if @cv.save redirect_to student_dashboard_path, notice: t('activerecord.successful.messages.created', model: @cv.class.model_name.human) else render 'new' end end Model: class Cv < ActiveRecord::Base attr_accessible :student_attributes belongs_to :student

How to use nested attributes with belongs_to association on new action?

廉价感情. 提交于 2019-12-24 17:55:00
问题 On the update action the following nested_form works, but on create I get this error: Couldn't find Student with ID=12 for Cv with ID= Controller: def new @cv = Cv.new @cv.student = current_student end def create @cv = Cv.new(params[:cv]) if @cv.save redirect_to student_dashboard_path, notice: t('activerecord.successful.messages.created', model: @cv.class.model_name.human) else render 'new' end end Model: class Cv < ActiveRecord::Base attr_accessible :student_attributes belongs_to :student

How to pass foreign key attributes down through a nested form in Rails 3

社会主义新天地 提交于 2019-12-24 15:25:11
问题 I have three models: class Client < ActiveRecord::Base has_many :balancesheets has_many :investment_assets, :through => :balancesheets class Balancesheet < ActiveRecord::Base belongs_to :client has_many :investment_assets, :dependent => :destroy accepts_nested_attributes_for :investment_assets, :allow_destroy => true class InvestmentAsset < ActiveRecord::Base belongs_to :balancesheet belongs_to :client I have two questions that have to do with the foreign key client_id. First, when I create a