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

  • Home
  • SEARCH
  • 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 8192151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:06:36+00:00 2026-06-07T04:06:36+00:00

I have an association as so: User has many Uploads Uploads belongs to User

  • 0

I have an association as so:

User has many Uploads
Uploads belongs to User and has many Upload Images
Upload Images belong to uploads <– Grandchild

I create my User before I add Uploads to that User. Uploads are stand-alone files of misc type, but they can also have many Upload Images linked to them to better describe the Upload (hence the seperate Upload Image model). Right now the Upload and Upload_Image persistence takes place in the users update function as they’re nested form attributes.

Because Uploads can have many Upload_Images I’m trying to use Uploadify to persist the images but I can’t get it sent along with the rest of the params hash to the Users update function (I used to be able to when it was just a single paperclip image upload being sent). Uploadify now forces me to send the Upload_Image params to a separate create action, which shouldn’t be a problem as I can simply calculate the upload_id foreign key and manually assign it.

The problem however is that when I perform a save it leaves the auto-generated fields i.e id and timestamps as nils, how can I prevent this?

Here’s my models(simplified):

User.rb

  has_many :uploads, :dependent => :destroy, :order => 'created_at desc'
  accepts_nested_attributes_for :uploads, :allow_destroy => true

Upload.rb

belongs_to :user
has_many :upload_images, :dependent => :destroy  
  accepts_nested_attributes_for :upload_images
    has_attached_file :upload,  :path => ":rails_root/:class/:id/:basename.:extension", :url => ":rails_root/:class  /:id/:basename.:extension"

UploadImage.rb

belongs_to :upload
has_attached_file :image, :styles => {:thumb => "125x125#", :small => "150x150>", :medium => "200x200>", :large => "320x240>"}, 
                  :path => ":rails_root/uploads/:upload_id/:class/:id/:style/:basename.:extension", 
                  :url => ":rails_root/uploads/:upload_id/:class/:id/:style/:basename.:extension"

Extra

Here’s my uploadify script:

<script type="text/javascript" charset="utf-8">
<%- session_key = Rails.application.config.session_options[:key] -%> 
$(document).ready(function() {
    // Create an empty object to store our custom script data
    var uploadify_script_data = {};

    // Fetch the CSRF meta tag data
    var csrf_token = $('meta[name=csrf-token]').attr('content');
    var csrf_param = $('meta[name=csrf-param]').attr('content');

    // Now associate the data in the config, encoding the data safely
    uploadify_script_data[csrf_token] = encodeURI(encodeURI(csrf_param));

    // Now associate the data in the config, encoding the data safely
    uploadify_script_data[csrf_token] = encodeURI(csrf_param)


    $('.uploadify').uploadify(
    {
        uploader : '/uploadify/uploadify.swf',
        cancelImg : '/uploadify/cancel.png',
        multi : true,
        auto : true,
        script : '/uploads',
        onComplete : function(event, queueID, fileObj, response, data) 
        { 
            var dat = eval('(' + response + ')');
            $.getScript(dat.upload);
        },
        scriptData : 
        {
            '_http_accept': 'application/javascript',
            'format' : 'json',
            '_method': 'post',
            '<%= session_key %>' : encodeURIComponent('<%= u cookies[session_key] %>'),
            'authenticity_token': encodeURIComponent('<%= u form_authenticity_token %>'),
            'upload_id' : '<%= Upload.last.id + 1 %>'
          }
    }); 

    $('#submit').click(function(event){ 
        event.preventDefault();
    }); 


    $('#submit').click(function(event){ 
            event.preventDefault(); 
            $('.uploadify').uploadifyUpload(); 
        });

}); 
</script>

And the create action:

  def create
    @upload_image_test = UploadImage.new(:image => params[:Filedata])
    @upload_image_test.upload_id = Upload.last.id + 1     
  end
  • 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-07T04:06:37+00:00Added an answer on June 7, 2026 at 4:06 am

    This was more of a design issue than anything. Basically I was attempting to create a child object before the parent so I simply needed to move this form to a separate page that takes place after the parent was created.

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

Sidebar

Related Questions

Let's say I have an association where User has and belongs to many Roles.
I have two models User and Category that have a HABTM association. I would
Right now I have 3 tables: User, Roles, and User_Roles for the many-to-many association.
I have a one to many association in rails where a user has_many :albums
I have a model Client which has many :tours, association in it. I am
I have a Post model that has a polymorphic association with a Vote model:
I have a User model which has many projects and a Project model which
I have a model app which has many to many association with users. Here
I have three entities: User, Office and PhoneNumber. The user has many phone numbers,
I have a User and Account models with has_one association and nested attributes. My

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.