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 6599369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:28:58+00:00 2026-05-25T18:28:58+00:00

I have a form for a model which accepts nested attrs for several other

  • 0

I have a form for a model which accepts nested attrs for several other models:

class Page < ActiveRecord::Base

  belongs_to :user
  has_many :images
  has_many :videos
  has_many :options

  accepts_nested_attributes_for :images
  accepts_nested_attributes_for :videos
  accepts_nested_attributes_for :options

  def active?
    published # boolean field
  end

end

I’d like the page owner (user) to be able to edit the page and its nested attrs, and see those changes immediately without needing to save the model (which would make it publicly viewable). My gut reaction is to clone the Page along with all its associations (yikes!) so that the original stays intact until the owner is satisfied with the changes to the clone.

Is there a more sensible or efficient solution?

  • 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-05-25T18:28:58+00:00Added an answer on May 25, 2026 at 6:28 pm

    EDIT – After looking into has_draft which is option 2 – I would 100% go with that.

    You have 3 options here:

    Option 1 –

    You can save the data into a session and retrieve it accordingly.

    Option 2 –

    You can use a draft plugin/gem like “has_draft” which will clone your model structure, create a new table, etc and handle all of it for you.

    https://github.com/rubiety/has_draft

    Option 3 –

    (not sure if this will work exactly, but it’s my best guess)

    You can duplicate your page, add a new field to your page model called “duplicate_of” and when you hit your edit action, create a duplicate passing in id of the original page. Then in the update action check if it is a duplicate and if it is, overwrite the original and delete the duplicate.

      def edit
        @original = User.find(params[:user_id]).pages.find(params[:id])
        @clone.duplicate_of = @original.id
        @clone.active = false
        @page = User.find(params[:user_id]).pages.create(@clone.attributes)
      end
    
      def update
          #you will need to add something here to check if its a duplicate
          #to begin with and if it is...
    
          @page = User.find(params[:user_id]).pages.find(params[:id])
          @original = User.find(params[:user_id]).pages.find(@page.duplicate_of)
          if @original.update_attributes(params[:page])
            @page.destroy
          end
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three models presented in a multi-model form. class Parent < ActiveRecord::Base has_many
I have two models: Company and Person class Person < ActiveRecord::Base belongs_to :company end
I have a very simple issue: User model: class User < ActiveRecord::Base devise :database_authenticatable,
I have a Project model which accepts nested attributes for tasks. And Task has
Hello I have a model named Client which has nested models called Receiver and
So suppose I have the Person and Child models: class Person < ActiveRecord::Base has_many
I have a form which binds a model and a file upload using the
I have a jQuery Model windows which contains a form. On creating of the
I have a model Post which belongs_to one Section . There are two different
I currently have a form set up with nested models - all going according

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.