nested-attributes

Rails 5 create multiple child objects using parent object by the use of nested attributes

混江龙づ霸主 提交于 2019-12-08 12:39:08
问题 So, I'm fairly new to Rails and I'm stuck due to my model's complexity. I have a Developer model, a Township model and a Project model and their contents are as follows:- Developer.rb Class Developer < ApplicationRecord has_many :townships, has_many :projects, through: :townships accepts_nested_attributes_for :township end Township.rb Class Township < ApplicationRecord belongs_to :developer has_many :projects accepts_nested_attributes_for :project end Project.rb Class Project <

Rails 3 Uploadify + Paperclip Can't Auto-Generate Grandchild Record ID On Save

社会主义新天地 提交于 2019-12-08 11:09:07
问题 I have an association as so: User has many Uploads Uploads belongs to User and has many Upload Images Upload Images belong to uploads <-- Grandchild I create my User before I add Uploads to that User. Uploads are stand-alone files of misc type, but they can also have many Upload Images linked to them to better describe the Upload (hence the seperate Upload Image model). Right now the Upload and Upload_Image persistence takes place in the users update function as they're nested form attributes

Rails: Access params of a form with a nested model

为君一笑 提交于 2019-12-08 10:28:47
问题 I have the following models class GymUser < ActiveRecord::Base belongs_to :user belongs_to :gym end class User < ActiveRecord::Base has_many :gym_users has_one :gym attr_accessible :gym_users_attributes, :gym_users accepts_nested_attributes_for :gym_users end I have a form for a new user, with a nested model gym_user. I want to make sure the user doesn't exist already. This is what I'm trying: def create_member @user = User.new(params[:user]) @user.generate_password @dupe = User.find_all_by

trouble saving data from nested attributes in rails

江枫思渺然 提交于 2019-12-08 10:19:22
问题 I am having an absolute nightmare trying to get these models to save. The parent model is called Galleries and the child is exhibition images. The form is nested. When I attempt to update the attributes in the form, they are not saved. I am not sure exactly where the problem is. Help would be greatly appreciated. class GalleriesController < ApplicationController def new @gallery = Gallery.new end def create end def update @gallery = Gallery.friendly.find params[:id] if @gallery.save(gallery

Rails Nested attributes with check_box loop

淺唱寂寞╮ 提交于 2019-12-08 08:43:24
问题 So I have a categories model class Category < ActiveRecord::Base has_many :provider_categories has_many :providers, :through => :provider_categories end and a provider model class Provider < ActiveRecord::Base has_many :provider_categories has_many :categories, :through => :provider_categories accepts_nested_attributes_for :provider_categories, :allow_destroy => true end here is my provider_category model class ProviderCategory < ActiveRecord::Base belongs_to :provider belongs_to :category

Nested attributes of uploaded image not being saved

拟墨画扇 提交于 2019-12-08 06:15:27
问题 I use Refile to attach images. Given the following models: class User < ActiveRecord::Base has_many :avatars, dependent: :destroy accepts_attachments_for :avatars, attachment: :file, append: true accepts_nested_attributes_for :avatars, :allow_destroy => true end class Avatar < ActiveRecord::Base belongs_to :user attachment :file end I have been trying to store the image metadata—in particular, the filename, size, and content type—in the database. To do this, I added the necessary columns to

Has_Many Through Associations and Nested Attributes

吃可爱长大的小学妹 提交于 2019-12-08 03:31:28
I'm trying to create a view allowing me to create and edit values of my joining table directly. This model is called 'hires'. I need to be able to create multiple rows in my joining table for when a child hires up to 2 books. I'm having some trouble and I suspect it's down to my associations... I have 3 models. Each Child can have 2 books: class Child < ActiveRecord::Base has_many :hires has_many :books, through: :hires end class Hire < ActiveRecord::Base belongs_to :book belongs_to :child accepts_nested_attributes_for :book accepts_nested_attributes_for :child end class Book < ActiveRecord:

nested model attributes + wicked wizard form not working

北城余情 提交于 2019-12-07 11:17:29
I am making an app based on the railscast tutorial 346(Wicked gem) and 196(nested model). I am trying to combine these 2 together and I am stuck because strong param attributes are not saving. So my app goes like this: I have a user, work, and education model. user.rb: has_many :educations, dependent: :destroy has_many :works, dependent: :destroy accepts_nested_attributes_for :educations, :works education.rb belongs_to :user work.rb belongs_to :user And then i generated the wicked wizard controller which i called UserStepsController: include Wicked::Wizard steps :education, :work def show

Rails 5 error message: Child-Model Parent-Model must exist

跟風遠走 提交于 2019-12-07 07:58:47
问题 I have two models, Parent is Property, child is Phone. When attempting to create a new Property record with nested Phone data, I receive an error message: Phones property must exist. I've studied the Rails Guide and a number of other documents without determining the cause. Here is a public github link if you want to see all the code: https://github.com/allenroulston/testnest.git class Property < ApplicationRecord has_many :phones accepts_nested_attributes_for :phones end class Phone <

Plural for fields_for has_many association not showing in view

杀马特。学长 韩版系。学妹 提交于 2019-12-07 06:52:00
问题 Currently, an Item belongs_to a Company and has_many ItemVariants . I'm trying to use nested fields_for to add ItemVariant fields through the Item form, however using :item_variants does not display the form. It is only displayed when I use the singular. I have check my associations and they seem to be correct, could it possibly have something to do with item being nested under Company, or am I missing something else? Thanks in advance. Note: Irrelevant code has been omitted from the snippets