nested-attributes

Rails 4 deleting nested attributes, works on create but not on edit/update

一笑奈何 提交于 2019-12-03 01:50:47
So I'm working from this Railscast . And I'm aware that there have been some changes in Rails 4 for Strong parameters. First relevant question . Second relevant question I've quadruple checked my implementation, but can't see where I'm going wrong. As it is at the moment, ticking the "destroy" box when submitting the patient initially (i.e. the create method) works as intended, and will delete any medication that has a checked box and permitting any that does not (from the three form inputs it provides). However when I subsequently edit that patient, any medications that don't get checked to

Unpermitted parameters nested attributes - rails

a 夏天 提交于 2019-12-02 18:15:16
问题 I'm trying to submit a form to 2 tables but somehow I got this syntax error unexpected '\n' at this line joins: ['sources'], :landslide_id and found unpermitted parameter: sources in landslide params. Here's all the files Models class Landslide < ApplicationRecord has_many :sources, dependent: :destroy accepts_nested_attributes_for :sources class Source < ApplicationRecord belongs_to :landslide end landslides_controller.rb def new @landslide = Landslide.new @landslide.sources.build end # POST

Nested form update action producing duplicate results

喜夏-厌秋 提交于 2019-12-02 10:49:56
问题 During the update action of a nested form, instead of updating the current nested records, it seems to create new nested records. This is what my controller looks like : class ApplicationsController < ApplicationController before_filter :set_user_and_job def new job = params[:job_id] @application = Application.build(job) end def create @application = Application.new(application_params) @application.save redirect_to root_url, :notice => "You have now applied!" end def edit @application =

Unpermitted parameters nested attributes - rails

我们两清 提交于 2019-12-02 10:34:26
I'm trying to submit a form to 2 tables but somehow I got this syntax error unexpected '\n' at this line joins: ['sources'], :landslide_id and found unpermitted parameter: sources in landslide params. Here's all the files Models class Landslide < ApplicationRecord has_many :sources, dependent: :destroy accepts_nested_attributes_for :sources class Source < ApplicationRecord belongs_to :landslide end landslides_controller.rb def new @landslide = Landslide.new @landslide.sources.build end # POST /landslides def create @landslide = Landslide.new(landslide_params) @landslide.save end private # Use

Nested form update action producing duplicate results

久未见 提交于 2019-12-02 07:18:36
During the update action of a nested form, instead of updating the current nested records, it seems to create new nested records. This is what my controller looks like : class ApplicationsController < ApplicationController before_filter :set_user_and_job def new job = params[:job_id] @application = Application.build(job) end def create @application = Application.new(application_params) @application.save redirect_to root_url, :notice => "You have now applied!" end def edit @application = Application.find(params[:id]) @answers = [] @job.questions.each do |question| @application.answers.each do

AJAX update of accepts_nested_attributes_for partials

删除回忆录丶 提交于 2019-12-02 05:45:59
My current working environment is Rails 2.3.8 (various reasons why my company hasn't moved to Rails 3). I'm trying to update elements of a multi-model form via AJAX calls - the idea being to replace certain dropdowns depending on how the user selects or fills in other fields. I have previously managed to get this working by using non-form based partials - the problem I have now is to reproduce the AJAX updating of the select dropdowns when the partials are based around form_for and fields_for. Sorry for the following wall of text - i've tried to cut it down as much as possible (the code itself

Validate number of nested attributes

自闭症网瘾萝莉.ら 提交于 2019-12-01 20:18:16
问题 I have a model with nested attributes : class Foo < ActiveRecord::Base has_many :bar accepts_nested_attributes_for :bar end It works fine. However I'd want to be sure that for every Foo, I have at least two Bar. I can't access the bar_attributes in my validations so it seems I can't validate it. Is there any clean way to do so ? 回答1: class Foo < ActiveRecord::Base has_many :bars accepts_nested_attributes_for :bar def validate if self.bars.reject(&:marked_for_destruction?).length < 2 self

Validate number of nested attributes

删除回忆录丶 提交于 2019-12-01 18:58:20
I have a model with nested attributes : class Foo < ActiveRecord::Base has_many :bar accepts_nested_attributes_for :bar end It works fine. However I'd want to be sure that for every Foo, I have at least two Bar. I can't access the bar_attributes in my validations so it seems I can't validate it. Is there any clean way to do so ? Tony Fontenot class Foo < ActiveRecord::Base has_many :bars accepts_nested_attributes_for :bar def validate if self.bars.reject(&:marked_for_destruction?).length < 2 self.errors.add_to_base("Must have at least 2 bars") end end end The controller will take care of

How do I Access Buttons inside a UserControl from xaml?

纵饮孤独 提交于 2019-12-01 16:30:17
At work I have several pages, each with buttons in the same places, and with the same properties. Each page also has minor differences. To that end, we created a userControl Template and put all the buttons in it, then applied that user control to all the pages. However, now it's rather hard to access the buttons and modify them from each page's xaml, because they are inside a UserControl on the page..... How do I elegantly access the buttons from each page? What I've tried: Currently, we bind to a bunch of dependency properties. I don't like this option because I have a lot of buttons, and

rails: create Parent, if doesn't exist, whilte creating child record

我与影子孤独终老i 提交于 2019-12-01 08:02:32
Any best practices for the following?: I have Manufacturer model that has_many Inventory In my new Inventory form I want a field that maps to Manufacturer.name so that when one submits the new Inventory form the app: searches for a manufacturer with the 'name' from the form if it exists then assign the id to @inventory.manufacturer_id and save @inventory if it doesn't exist then create the manufacturer with the 'name' from the form, assign the id to @inventory.manufacturer_id and save have validations work on the new Inventory form such that, if the the Inventory form fails validation on a