Created
August 19, 2014 13:48
-
-
Save SonVu/91b204c032f4fde53108 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _form.html.erb (Product) | |
| <% f.fields_for :product_images do |builder| %> | |
| <%= builder.text_field :image %> | |
| <% end %> | |
| ----------- | |
| class Product < ActiveRecord::Base | |
| has_many :product_images, dependent: :destroy | |
| accepts_nested_attributes_for :product_images | |
| end | |
| ----------- | |
| class ProductImage < ActiveRecord::Base | |
| has_attached_file :image, :stytles => {:medium => "250x250", :thumb => "140x140"}, :default_url => "/images/:style/missing.png" | |
| validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/ | |
| belongs_to :product | |
| end | |
| ----------- | |
| ProductController | |
| def new | |
| @product = Product.new | |
| 3.times {@product.product_images.build} | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment