Im working on a simple form function that adds an image through a nested form.
A photo model in which all my uploaded images should be stored.
class Photo < ActiveRecord::Base
belongs_to :posting
has_attached_file :image, styles: { large: "500x500>", medium: "300x300>", thumb: "100x100#" }, default_url: "/images/:style/missing.png"
validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/
end
fragment of my nested form (in form)
<%= post.fields_for :photos, html: { multipart: true } do |photo| %>
<%= photo.label :image %>
<%= photo.file_field :image %>
<% end %>
Everything is fine, but when I uncomment the line accepts_nested_attributes_for. My nested form disappears!
class Posting < ActiveRecord::Base
belongs_to :subcategory
belongs_to :category
has_many :photos
end
source
share