diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index 700812469..128115d6a 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -35,4 +35,19 @@ class PhotosController < ApplicationController @photo = Photo.where(:id => params[:id]).first @album = @photo.album end + + def edit + @photo= Photo.first(:id => params[:id]) + @album = @photo.album + end + + def update + @photo= Photo.first(:id => params[:id]) + if @photo.update_attributes(params[:photo]) + flash[:notice] = "Successfully updated photo." + redirect_to @photo + else + render :action => 'edit' + end + end end diff --git a/app/models/photo.rb b/app/models/photo.rb index cc9f3c412..a3143ae86 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -4,9 +4,11 @@ class Photo < Post mount_uploader :image, ImageUploader xml_accessor :remote_photo + xml_accessor :caption xml_reader :album_id key :album_id, ObjectId + key :caption, String belongs_to :album, :class_name => 'Album' diff --git a/app/views/photos/edit.html.haml b/app/views/photos/edit.html.haml new file mode 100644 index 000000000..c849b43b7 --- /dev/null +++ b/app/views/photos/edit.html.haml @@ -0,0 +1,21 @@ +%h1.big_text + .back + = link_to "⇧ #{@album.name}", album_path(@album) + = "Editing #{@photo.image}" + +%div{:id => @photo.id} + + #show_photo + = linked_scaled_photo @photo, @album + + = form_for @photo do |p| + = p.text_field :caption, :value => @photo.caption + = p.submit + + #content_bottom + .back + = link_to "⇧ #{@album.name}", album_path(@album) + -if mine? @album + .button.right + = link_to 'Delete Photo', @photo, :confirm => 'Are you sure?', :method => :delete + diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml index 0714ec692..d08790650 100644 --- a/app/views/photos/show.html.haml +++ b/app/views/photos/show.html.haml @@ -14,6 +14,9 @@ #show_photo = linked_scaled_photo @photo, @album + .caption + = @photo.caption + #next_prev_links = link_to_prev @photo, @album | diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 2c57c8a82..3f0cf9e93 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -264,6 +264,10 @@ ul.comment_set { min-height: 200px; } #show_photo img { max-width: 100%; } + #show_photo .caption { + margin-top: 10px; + margin-bottom: 25px; + font-size: larger; } #debug_info { margin-top: 20px; } diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 153661b15..fb2204dd5 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -319,6 +319,14 @@ ul.comment_set img :max-width 100% + .caption + :margin + :top 10px + :bottom 25px + :font + :size larger + + #debug_info diff --git a/spec/models/photo_spec.rb b/spec/models/photo_spec.rb index 721dc840a..dceed3a78 100644 --- a/spec/models/photo_spec.rb +++ b/spec/models/photo_spec.rb @@ -36,6 +36,13 @@ describe Photo do Photo.first.album.name.should == 'foo' end + it 'should have a caption' do + @photo.image.store! File.open(@fixture_name) + @photo.caption = "cool story, bro" + @photo.save + Photo.first.caption.should == "cool story, bro" + end + it 'should remove its reference in user profile if it is referred' do @photo.image.store! File.open(@fixture_name) @photo.save