Note that there are some explanatory texts on larger screens.

plurals
  1. PORails - paperclip - Multiple photo upload not saving
    text
    copied!<p>I'm trying to make a create product page in rails. This includes adding multiple images and text fields. I have one model for products and one for photos. I'm using the paperclip gem for photo upload. But I get no picture when I view product page. Photos are not being saved to database.</p> <p>P.S. I use HAML.</p> <p><strong>app/views/products/show.html.haml</strong></p> <pre><code> %b Name = @product.name %br %b Description = @product.description %br - @product.photos.each do |photo| = image_tag photo.image.url </code></pre> <p><strong>app/controllers/products_controller</strong></p> <pre><code>class ProductsController &lt; ApplicationController before_filter :require_login before_filter :current_user, only: [:create, :destory] def new @product = Product.new @photo = Photo.new 5.times { @product.photos.build } end def create @photo = current_user.photos.build(params[:photo]) @product = current_user.products.build(params[:product]) if @product.save render "show", :notice =&gt; "Sale created!" else render "new", :notice =&gt; "Somehting went wrong!" end end def show @product = Product.find(params[:id]) end </code></pre> <p><strong>app/models/photo</strong></p> <pre><code>class Photo &lt; ActiveRecord::Base attr_accessible :product_id belongs_to :product has_attached_file :image, :styles =&gt; { :thumb=&gt; "100x100#", :small =&gt; "300x300&gt;", :large =&gt; "600x600&gt;" } end </code></pre> <p><strong>app/models/product</strong></p> <pre><code>class Product &lt; ActiveRecord::Base attr_accessible :description, :name, :price, :condition, :ship_method, :ship_price, :quantity, :photo has_many :photos, dependent: :destroy accepts_nested_attributes_for :photos belongs_to :user end </code></pre> <p><strong>user model</strong></p> <pre><code> class User &lt; ActiveRecord::Base attr_accessible :email, :password, :password_confirmation, :name attr_accessor :password has_many :products, dependent: :destroy has_many :photos,:through=&gt;:products </code></pre> <p><strong>app/products/new.html.haml</strong></p> <pre><code>= form_for @product, :html =&gt; { :multipart =&gt; true } do |f| %p = fields_for :photos do |f_i| =f_i.file_field :image </code></pre>
 

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