check for photo existence before offering options or the file
parent
3dca339ab1
commit
7e0d757d20
|
@ -8,9 +8,9 @@ class Photos < Application
|
||||||
raise NotFound unless @photo
|
raise NotFound unless @photo
|
||||||
@secondary_title = h(@photo.filename)
|
@secondary_title = h(@photo.filename)
|
||||||
|
|
||||||
img = get_photo_version(600, 600)
|
img = get_photo_version(600, 600) rescue nil
|
||||||
@width = img.columns
|
@width = img.columns rescue 150
|
||||||
@height = img.rows
|
@height = img.rows rescue 150
|
||||||
|
|
||||||
render
|
render
|
||||||
end
|
end
|
||||||
|
@ -68,21 +68,24 @@ class Photos < Application
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def thumbnail
|
def send_rmagicked_image
|
||||||
only_provides :html
|
only_provides :html
|
||||||
@photo = Photo.find(params[:id])
|
@photo = Photo.find(params[:id])
|
||||||
raise NotFound unless @photo
|
raise NotFound unless @photo
|
||||||
send_data get_photo_version(150, 150).to_blob,
|
if @photo.exist?
|
||||||
|
w = case params[:action]
|
||||||
|
when 'screen'
|
||||||
|
600
|
||||||
|
else
|
||||||
|
150
|
||||||
|
end
|
||||||
|
send_data get_photo_version(w, w).to_blob,
|
||||||
:filename => @photo.filename, :disposition => 'inline',
|
:filename => @photo.filename, :disposition => 'inline',
|
||||||
:type => @photo.content_type
|
:type => @photo.content_type
|
||||||
|
else
|
||||||
|
send_file Merb.root + '/public/images/image-missing.png', :disposition => 'inline'
|
||||||
end
|
end
|
||||||
|
|
||||||
def screen
|
|
||||||
only_provides :html
|
|
||||||
@photo = Photo.find(params[:id])
|
|
||||||
raise NotFound unless @photo
|
|
||||||
send_data get_photo_version(600, 600).to_blob,
|
|
||||||
:filename => @photo.filename, :disposition => 'inline',
|
|
||||||
:type => @photo.content_type
|
|
||||||
end
|
end
|
||||||
|
alias_method :thumbnail, :send_rmagicked_image
|
||||||
|
alias_method :screen, :send_rmagicked_image
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,11 @@
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
width: <%= @width -%>px;
|
width: <%= @width -%>px;
|
||||||
height: <%= @height -%>px;
|
height: <%= @height -%>px;
|
||||||
|
<% if @photo.exist? -%>
|
||||||
background-image: url('/photos/screen/<%= @photo.id -%>');
|
background-image: url('/photos/screen/<%= @photo.id -%>');
|
||||||
|
<% else -%>
|
||||||
|
background-image: url('/images/image-missing.png');
|
||||||
|
<% end -%>
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
}
|
}
|
||||||
#photo_block_container {
|
#photo_block_container {
|
||||||
|
@ -203,9 +207,11 @@ function toggle_photo_tag_editor(direction)
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<% if @photo.exist? -%>
|
||||||
<div id="photo_tags">
|
<div id="photo_tags">
|
||||||
<%= partial 'photo_tags/photo_tags' %>
|
<%= partial 'photo_tags/photo_tags' %>
|
||||||
</div>
|
</div>
|
||||||
|
<% end -%>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
//<![CDATA[
|
//<![CDATA[
|
||||||
|
@ -223,9 +229,9 @@ function toggle_photo_tag_editor(direction)
|
||||||
|
|
||||||
<% throw_content :for_sidebar do -%>
|
<% throw_content :for_sidebar do -%>
|
||||||
<a href="<%= url(:album, :id => @photo.album.name.gsub(/ /, '_')) -%>"><img src="/images/camera-photo.png" /> Back to <%= @photo.album.name -%></a><br />
|
<a href="<%= url(:album, :id => @photo.album.name.gsub(/ /, '_')) -%>"><img src="/images/camera-photo.png" /> Back to <%= @photo.album.name -%></a><br />
|
||||||
<% if allowed_to?(:edit_photo, @photo) -%><a href="<%= url(:edit_photo, :id => @photo.id) -%>" rel="nofollow"><img src="/images/document-save.png" /> Edit photo</a><br /><% end %>
|
<% if allowed_to?(:edit_photo, @photo) and @photo.exist? -%><a href="<%= url(:edit_photo, :id => @photo.id) -%>" rel="nofollow"><img src="/images/document-save.png" /> Edit photo</a><br /><% end %>
|
||||||
<% if allowed_to?(:delete_photo, @photo) -%><a href="<%= url(:delete_photo, :id => @photo.id) -%>" onclick="if(!confirm('Are you sure you want to delete this photo?')){return false;}" rel="nofollow"><img src="/images/edit-delete.png" /> Destroy photo</a><br /><% end -%>
|
<% if allowed_to?(:delete_photo, @photo) -%><a href="<%= url(:delete_photo, :id => @photo.id) -%>" onclick="if(!confirm('Are you sure you want to delete this photo?')){return false;}" rel="nofollow"><img src="/images/edit-delete.png" /> Destroy photo</a><br /><% end -%>
|
||||||
<a href="<%= photo_url(@photo) -%>"><img src="/images/image-x-generic.png" /> Download original</a><br />
|
<% if @photo.exist? -%><a href="<%= photo_url(@photo) -%>"><img src="/images/image-x-generic.png" /> Download original</a><br /><% end -%>
|
||||||
<% if allowed_to?(:upload_images) -%><a href="<%= url(:new_photo, :photo => { :album_id => @photo.album_id }) -%>"><img src="/images/emblem-photos.png" /> Upload Image</a><br /><% end %>
|
<% if allowed_to?(:upload_images) -%><a href="<%= url(:new_photo, :photo => { :album_id => @photo.album_id }) -%>"><img src="/images/emblem-photos.png" /> Upload Image</a><br /><% end %>
|
||||||
<% if allowed_to?(:tag_photo) -%><span id="show_photo_tag_editor"><a href="#" onclick="toggle_photo_tag_editor(true)"><img src="/images/face-monkey.png" /> Tag Image</a></span><span id="hide_photo_tag_editor" style="display: none;"><a href="#" onclick="toggle_photo_tag_editor(false); return false;"><img src="/images/face-monkey.png" /> Done Tagging</a></span><br /><% end %>
|
<% if allowed_to?(:tag_photo) and @photo.exist? -%><span id="show_photo_tag_editor"><a href="#" onclick="toggle_photo_tag_editor(true)"><img src="/images/face-monkey.png" /> Tag Image</a></span><span id="hide_photo_tag_editor" style="display: none;"><a href="#" onclick="toggle_photo_tag_editor(false); return false;"><img src="/images/face-monkey.png" /> Done Tagging</a></span><br /><% end %>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
Reference in New Issue