Skip to content

Instantly share code, notes, and snippets.

@esparkman
Created September 2, 2010 18:43
Show Gist options
  • Save esparkman/562711 to your computer and use it in GitHub Desktop.
Save esparkman/562711 to your computer and use it in GitHub Desktop.
class Photo < ActiveRecord::Base
belongs_to :project, :dependent => :destroy
has_attached_file :data, :styles => { :medium => "300x300>", :thumb => "100x100>" }
validates_attachment_content_type :data, :content_type => 'image/jpeg', :message => "has to be in jpeg format"
end
class Project < ActiveRecord::Base
attr_accessor :photo_remove
attr_accessible :name, :description, :url, :photos_attributes
validates_presence_of :name
has_many :photos, :dependent => :destroy
accepts_nested_attributes_for :photos, :allow_destroy => true
def photo_remove=(remove)
self.photo = nil if remove == '1'
end
end
<% for photo in @project.photos %>
<p><%= image_tag(photo.data(:thumb)) %></p>
<label>Delete</label><%= check_box :photo, :photo_remove %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment