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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:51:04+00:00 2026-05-19T21:51:04+00:00

I am reading this tutorial : http://sleekd.com/general/adding-multiple-images-to-a-rails-model-with-paperclip/ because i need Save the product images

  • 0

I am reading this tutorial : http://sleekd.com/general/adding-multiple-images-to-a-rails-model-with-paperclip/
because i need Save the product images in a independent model. However when Product.create execute don´t save the data for product images model.

NOTE: I use the new pack action because i need to use ajax for create a new product.

Please I need Help.

My Code

Controllers

    class Admin::PacksController < ApplicationController
      def new
        @pack = Pack.new
        @product = Product.new
        4.times {@product.product_images.build} # added this
        respond_to do |format|
          format.html # new.html.erb
          format.xml  { render :xml => @pack }
        end
      end

      def create_starred_product
        product = Product.new(params[:product])
        product.save
...

      end

View

<% form_remote_for @product, :url => {:controller => "products", :action => "create_starred_product"}, :html => {:multipart => true} do |f| %>
      <div id="content">
....#OTHER FIELDS OF PRODUCT. ITS SAVE METHOD IS OK
        <div id="images-selector">
          <span class="fleft">Imágenes</span><br/>
          <% count = 0 %>
          <% f.fields_for :product_images do |builder| %>

              <% if builder.object.new_record? %>
                  <label>
                    Imagen <%= "#{count = count + 1}" %>
                  </label>
                  <%= builder.file_field :photo, :class => "textarea" -%><br/>
              <% end %>
          <% end %>
        </div>
        <p><%= f.submit "Crear" %></p>
      </div>
  <% end %>

Models

class Product < ActiveRecord::Base
  has_many :packs, :through => :pack_products
  has_many :product_images, :dependent => :destroy
  #PAPERCLIP
  accepts_nested_attributes_for :product_images, :reject_if => lambda { |t| t['product_image'].blank? }
end

class ProductImage < ActiveRecord::Base
  belongs_to :product
  has_attached_file :photo, :url => "/:attachment/:class/:id/:style_:basename.:extension", :styles => { :medium => "300x300>", :thumb => "100x100>", :small => "30x30>" }
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-05-19T21:51:04+00:00Added an answer on May 19, 2026 at 9:51 pm

    You can’t upload files using AJAX, just like you said. There are, however, alternate solutions.

    The common technique to accomplish this is the usage of an iframe. Have a look here, this tutorial is oriented towards attachment_fu but it’ll work with paperclip as well. Uploadify is worth checking out and can also be used with paperclip on rails 2.3 and rails 3.

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

Sidebar

Related Questions

I was reading this tutorial from the DNN website http://www.dotnetnuke.com/Community/Blogs/tabid/825/EntryId/2675/DotNetNuke-Skinning-101-Part-2.aspx I found the tutorial
I was reading up on this javascript tutorial: http://www.switchonthecode.com/tutor...ccordion-menus Basically, it shows you how
I am reading this tutorial: http://blog.dhavalparikh.co.in/2009/06/step-by-step-twitter-oauth-integration-with-rails/ OK, first redirect to twitter connect page. When
I'm reading this section of Java EE tutorial. http://download.oracle.com/javaee/6/tutorial/doc/bncfu.html#bncfy And have a question: If
i am reading this page http://www.cplusplus.com/doc/tutorial/exceptions.html it says if i write function() throw(); no
I'm new to iOS programming and I'm reading this tutorial to get along http://www.raywenderlich.com/1797/how-to-create-a-simple-iphone-app-tutorial-part-1
Reading this article http://support.microsoft.com/kb/813878 I have a question: Where can I get ipseccmd.exe for
After reading this: http://docs.djangoproject.com/en/dev/ref/contrib/csrf/#how-to-use-it I came to the conclusion that it is not valid
I'm following this tutorial here: http://brenelz.com/blog/implementing-paging-using-php-and-jquery/ Here is what I have: http://eataustineat.com/testingfolder/ I've encountered
Sort of a novice javascript person reading a backbone.js tutorial http://arturadib.com/hello-backbonejs/docs/5.html and have a

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.