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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:20:13+00:00 2026-05-26T13:20:13+00:00

Is it possible to save a file in a dependent model entity when the

  • 0

Is it possible to save a file in a dependent model entity when the parent (base) entity has not yet been saved?

I would like the user to be able to add images to a story prior to the story actually being saved. So my model is like this:

Story (Base Entity) has_many :pictures
  + Picture (Depedent Entity) belongs_to :story

In the Story controller, I have a separate action called add_image. However, because the instance variable @story does not seem to be persisted across requests, I cannot access it in this action.

What I have thought of doing so far is to store the @story variable in the session on create, so I can retrieve it from there. Will this work? May it have any unintended side-effects for subsequent requests? (E.g. what if I have the previous story stored in the session and add a picture to the wrong story?).

  • 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-26T13:20:13+00:00Added an answer on May 26, 2026 at 1:20 pm

    Apparently it is possible to save dependent records together with the main on first create:

    http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html

    See the section “Unsaved objects and associations”. You must use collection.build to add the dependent records.

    Now my problem is still how to reliably persist the parent across requests, though I am thinking this may be possible by storing it in the session with the ID generated by mongoid (the only problem being that it is not portable across ORMs, I think).

    This answers part of my question. So I will not accept any answer just yet, and once I have found a proper solution, I will give an update.

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

Sidebar

Related Questions

I had a quick question. Is it possible to save a file without actually
Is it possible to save a form in VBA as .exe file and then
Possible Duplicate: Create Excel file in Java How to save output in excel format
When working with htaccess files on Windows, is it possible to save the file
Is it possible to save the layout diagram from a DBML file as a
Is it possible to save STL map to file? and I can load the
Is it possible to save a whole C# solution in one single text file?
Using Javascript is it possible to listen for browser's file open/save dialog box event.
Is that possible to save colorcodes in Plist file somehow? Do I have to
in Zend-Framework, is it possible to save an altered .ini-File? Because altering the $config-Array

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.