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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:41:51+00:00 2026-06-16T16:41:51+00:00

I have a form where users can upload assets using ajax. This creates many

  • 0

I have a form where users can upload assets using ajax. This creates many Asset objects that I then want to associate with a Post object when it is created. I have a form_field named asset_ids that I update with the created Asset ids as they are created. When I create the Post object and populate its data with assign_attributes, only ONE association is created, no matter how many ids are there.

Asset model:

class Asset < ActiveRecord::Base

  attr_accessible :caption, :image
  belongs_to :post
  has_attached_file :image, :styles => { :large => "600x600>", :medium => "300x300>", :thumb => "100x100>" }

end

Post model:

class Post < ActiveRecord::Base

    attr_accessible :content, :post_date, :status, :title, :tag_list, :asset_ids, :as => :admin
    has_many :assets, :dependent => :destroy
    has_and_belongs_to_many :tags

    validates :content, :post_date, :title, :presence => true

end

An example of the posted data hash:

{"title"=>"Test post", "status"=>"true", "post_date"=>"01/02/2013", "content"=>"&nbsp;Some content", "tag_list"=>"", "asset_ids"=>"97,102"}

The example above assigns only one Asset (id 97) to the new Post, when I assign_attributes like so:

@post = Post.new
@post.assign_attributes params[:post], :as => :admin
  • 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-16T16:41:52+00:00Added an answer on June 16, 2026 at 4:41 pm

    I had to make sure I was assigning the ids as an array:

    @post.asset_ids = params[:post][:asset_ids].split(",")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have this script where users (using a form where they can upload
I have a form where users can modify a collection of objects using a
I have an upload form where users can upload images that are currently being
I have a product form that users can upload 5 pictures simultaneously. Everything is
I have a form in my django app where users can upload files. How
If I have form where user can upload files via Ajax (and upload is
I have a dynamic form that users can add/delete sets of input fields. I
I have a form from which users can select 100s of files to upload
I have an HTML web form where users can upload multiple files. I am
I have a form which I am using to upload users photos but the

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.