nested-attributes

How to set values of nested parameters in Rails 4 from controller method?

白昼怎懂夜的黑 提交于 2019-12-13 02:07:52
问题 I have request model and nested model filled_cartridges when I create new request object i also need to set the values of nested params inside create controller method. I have many nested params so i need to iterate through them, something like that: params[:request][:filled_cartridges_attributes].each do |_,value| # here i try to set :client_id parameter, which is nested # where @client.id is defined value[:client_id] = @client.id # i am pretty sure that the problem is here # is it a correct

Rails 4 - nested attributes with Cocoon gem

不羁岁月 提交于 2019-12-13 01:34:54
问题 I'm trying to make an app with Rails 4. I'm using Cocoon gem for nested forms with simple form. I have a qualifications model, nested in a profile model. The associations are: Qualifications belongs_to :profile Profile has_many :qualifications accepts_nested_attributes_for :qualifications, reject_if: :all_blank, allow_destroy: true In my profile form, I incorporate the qualifications attributes with: <%= f.simple_fields_for :qualifications do |f| %> <%= render 'qualifications/qualification

MVC4 adding/deleting from nested collections (with jQuery?)

非 Y 不嫁゛ 提交于 2019-12-13 01:16:21
问题 I'm trying to learn ASP.net MVC after working with webforms for a long time, so apologies if I'm confusing things. I'm having trouble moving beyond the simple edit page-per-model structure. I have Employees, who are xrefed to Projects, and I want to edit this all on one page. I have an Employee model: public class Employee { public string UserID { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public List<ProjectXref> Projects { get; set; } } And here's

Rails - Cocoon gem - Nested Forms

廉价感情. 提交于 2019-12-12 18:38:30
问题 I am trying to make an app with Rails 4. I use simple form gem for forms and am trying to use Cocoon gem for nested elements of the forms. I asked this question, which explains what I'm trying to achieve in more detail: Rails - Multiple entries for a single attribute I have a profile model and a qualifications model. The associations are: profile.rb has_many :qualifications accepts_nested_attributes_for :qualifications, reject_if: :all_blank, allow_destroy: true qualification.rb belongs_to

Rails: Polymorphic assosiation and accepts_nested_attributes

烈酒焚心 提交于 2019-12-12 10:19:55
问题 The attachment won't save. What I am missing here? In my application I have a project ,for each project user can upload many assets. The Upload is done by carrier wave. here are the models class Project < ActiveRecord::Base has_many :assets,:as => :assetable,dependent: :destroy accepts_nested_attributes_for :assets, :allow_destroy => true end class Asset < ActiveRecord::Base belongs_to :project belongs_to :user belongs_to :assetable, :polymorphic => true mount_uploader :attachment,

Rails: How to make available parent attribute in setter method

試著忘記壹切 提交于 2019-12-12 09:52:15
问题 Context: I have a company model with many projects , having many tasks . The company also has many employees , which in turn have many tasks . Schema: Problem: I'm building a form to create a project where the user can add multiple tasks . Upon submission the form should create a single project record, one or more task records with hours and employee_id attributes and (!) check if the employee name already exists in the database or create a new one. I've approached this by adding jquery

Validate presence of nested attributes within a form

隐身守侯 提交于 2019-12-12 09:44:58
问题 I have the following associations: #models/contact.rb class Contact < ActiveRecord::Base has_many :contacts_teams has_many :teams, through: :contacts accepts_nested_attributes_for :contacts_teams, allow_destroy: true end #models/contacts_team.rb class ContactsTeam < ActiveRecord::Base belongs_to :contact belongs_to :team end #models/team.rb class Team < ActiveRecord::Base has_many :contacts_team has_many :contacts, through: :contacts_teams end A contact should always have at least one

Can't mass-assign protected attributes for creating a has_many nested model with Devise

我的未来我决定 提交于 2019-12-12 08:33:00
问题 I've watched the RailsCast, another nested attributes video, lots of SO posts, and fought with this for a while, but I still can't figure it out. I hope it's something tiny. I have two models, User (created by Devise), and Locker (aka, a product wishlist), and I'm trying to create a Locker for a User when they sign up. My login form has a field for the name of their new Locker (aptly called :name ) that I'm trying to assign to the locker that gets created upon new user registration. All I'm

first_or_create by email and then save the nested model

扶醉桌前 提交于 2019-12-12 07:56:21
问题 I two models User and Submission as follows: class User < ActiveRecord::Base # Associations has_many :submissions accepts_nested_attributes_for :submissions # Setup accessible (or protected) attributes for your model attr_accessible :email, :name, :role, :submission_ids, :quotation_ids, :submissions_attributes validates :email, :presence => {:message => "Please enter a valid email address" } validates :email, :uniqueness => { :case_sensitive => false } end class Submission < ActiveRecord:

ActiveAdmin not saving has_many nested object

南笙酒味 提交于 2019-12-12 06:25:25
问题 I cannot seem to find out why my has_many record will not save. I've test with has_one in the models and it works fine but when I change it to has_many it doesn't work. I've check a few simular stackoverflow posts and I seem to have this correct but it doesn't work. Nested form in activeadmin not saving updates & ActiveAdmin Form not saving nested object This is for Rails version 5.1.0.alpha and Activeadmin version 1.0.0.pre4 I do not get any errors nor do I see the nested object get created