Created
September 2, 2010 18:43
-
-
Save esparkman/562711 to your computer and use it in GitHub Desktop.
This file contains 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
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 |
This file contains 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
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 |
This file contains 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
<% 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