Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8932601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:21:02+00:00 2026-06-15T09:21:02+00:00

I’m trying to build a form that allows users to update some records. They

  • 0

I’m trying to build a form that allows users to update some records. They can’t update every field, though, so I’m going to do some explicit processing (in the controller for now) to update the model vis-a-vis the form. Here’s how I’m trying to do it:

Family model:

class Family < ActiveRecord::Base
  has_many :people, dependent: :destroy
  accepts_nested_attributes_for :people, allow_destroy: true, reject_if: ->(p){p[:name].blank?}
end

In the controller

def check
  edited_family = Family.new(params[:family])
  #compare to the one we have in the db
  #update each person as needed/allowed
  #save it
end

Form:

= form_for current_family, url: check_rsvp_path, method: :post do |f|
  = f.fields_for :people do |person_fields|
    - if person_fields.object.user_editable
      = person_fields.text_field :name, class: "person-label"
    - else
      %p.person-label= person_fields.object.name

The problem is, I guess, that Family.new(params[:family]) tries to pull the people out of the database, and I get this:

ActiveRecord::RecordNotFound in RsvpsController#check

Couldn't find Person with ID=7 for Family with ID=

That’s, I guess, because I’m not adding a field for family id to the nested form, which I suppose I could do, but I don’t actually need it to load anything from the database for this anyway, so I’d rather not. I could also hack around this by just digging through the params hash myself for the data I need, but that doesn’t feel a slick. It seems nicest to just create an object out of the params hash and then work with it.

Is there a better way? How can I just create the nested object?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:21:03+00:00Added an answer on June 15, 2026 at 9:21 am

    I ended up taking @244an’s suggestion:

    class Person < ActiveRecord::Base
      belongs_to :family
    
      def temp_id
        @temp_id || self.id
      end
    
      def temp_id=(new_id)
        @temp_id = new_id
      end
    end
    

    In the form:

    = form_for current_family, url: check_rsvp_path, method: :post, html: {class: "form-inline"} do |f|
      #people-list
        = f.fields_for :people, include_id: false do |person_fields|
          = person_fields.hidden_field :temp_id
          #rest of the form here
    

    Then in my controller:

    def check
        @edited_family = Family.new(params[:family])
    
        current_people = Hash[current_family.people.map{|p| [p.id, p]}]
    
        @edited_family.people.each do |person|
          current_person = current_people[person.temp_id.to_i]
    
          next unless current_person
    
          current_person.name = person.name if current_person.user_editable
          current_person.attending = person.attending
          current_person.save!
        end
    
        current_family.responded = true
        current_family.save!
    
      end
    

    The reason I added that field to the model was that I couldn’t come up with a good way of using hidden_field to rename the field.

    Anyway, it feels superhacky, but it works. What I’d have really wanted was just a way to tell new not to try to match child objects to the DB even if they have ids.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.