Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem paperclip with ajax
    primarykey
    data
    text
    <p>I am reading this tutorial : <a href="http://sleekd.com/general/adding-multiple-images-to-a-rails-model-with-paperclip/" rel="nofollow">http://sleekd.com/general/adding-multiple-images-to-a-rails-model-with-paperclip/</a> 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.</p> <p>NOTE: I use the new pack action because i need to use ajax for create a new product.</p> <p>Please I need Help.</p> <p>My Code</p> <p>Controllers</p> <pre><code> class Admin::PacksController &lt; 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 =&gt; @pack } end end def create_starred_product product = Product.new(params[:product]) product.save ... end </code></pre> <p>View</p> <pre><code>&lt;% form_remote_for @product, :url =&gt; {:controller =&gt; "products", :action =&gt; "create_starred_product"}, :html =&gt; {:multipart =&gt; true} do |f| %&gt; &lt;div id="content"&gt; ....#OTHER FIELDS OF PRODUCT. ITS SAVE METHOD IS OK &lt;div id="images-selector"&gt; &lt;span class="fleft"&gt;Imágenes&lt;/span&gt;&lt;br/&gt; &lt;% count = 0 %&gt; &lt;% f.fields_for :product_images do |builder| %&gt; &lt;% if builder.object.new_record? %&gt; &lt;label&gt; Imagen &lt;%= "#{count = count + 1}" %&gt; &lt;/label&gt; &lt;%= builder.file_field :photo, :class =&gt; "textarea" -%&gt;&lt;br/&gt; &lt;% end %&gt; &lt;% end %&gt; &lt;/div&gt; &lt;p&gt;&lt;%= f.submit "Crear" %&gt;&lt;/p&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>Models</p> <pre><code>class Product &lt; ActiveRecord::Base has_many :packs, :through =&gt; :pack_products has_many :product_images, :dependent =&gt; :destroy #PAPERCLIP accepts_nested_attributes_for :product_images, :reject_if =&gt; lambda { |t| t['product_image'].blank? } end class ProductImage &lt; ActiveRecord::Base belongs_to :product has_attached_file :photo, :url =&gt; "/:attachment/:class/:id/:style_:basename.:extension", :styles =&gt; { :medium =&gt; "300x300&gt;", :thumb =&gt; "100x100&gt;", :small =&gt; "30x30&gt;" } end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload