Commit 31ded4f2
Changed files (3)
app
app/controllers/photos_controller.rb
@@ -16,21 +16,17 @@ class PhotosController < ApplicationController
end
def create
- p_attr = params[:photo]
- p_attr[:image] = params[:photo][:image].first if params[:photo][:image].class == Array
+ attributes = params[:photo]
+ attributes[:image] = params[:photo][:image].first if params[:photo][:image].class == Array
- @photo = @creation.photos.build(p_attr)
+ @photo = @creation.photos.build(attributes)
if @photo.save
respond_to do |format|
- format.html {
- render :json => [@photo.to_jq_upload].to_json, :content_type => 'text/html', :layout => false
- }
- format.json {
- render :json => [@photo.to_jq_upload].to_json
- }
+ format.html { render :json => [@photo.to_jq_upload].to_json, :content_type => 'text/html', :layout => false }
+ format.json { render :json => [@photo.to_jq_upload].to_json }
end
else
- render :json => [{:error => "custom_failure"}], :status => 304
+ render :json => [{:error => "oops... we're sorry but we weren't able to upload your photo."}], :status => 304
end
end
app/models/photo.rb
@@ -7,14 +7,25 @@ class Photo < ActiveRecord::Base
include Rails.application.routes.url_helpers
def to_jq_upload
- {
- "name" => read_attribute(:image),
- "size" => image.size,
- "url" => image.url,
- "thumbnail_url" => image.thumb.url,
- "delete_url" => id,
- "delete_type" => "DELETE"
- }
+ if image.thumb.url
+ {
+ "name" => read_attribute(:image),
+ "size" => image.size,
+ "url" => image.url,
+ "thumbnail_url" => image.thumb.url,
+ "delete_url" => id,
+ "delete_type" => "DELETE"
+ }
+ else
+ {
+ "name" => read_attribute(:image),
+ "size" => image.size,
+ "url" => image.url,
+ "thumbnail_url" => image.url,
+ "delete_url" => id,
+ "delete_type" => "DELETE"
+ }
+ end
end
def watermark
app/views/photos/_form.html.erb
@@ -78,7 +78,7 @@
<td class="error" colspan="2"><span class="label label-important">Error</span> {%=file.error%}</td>
{% } else { %}
<td class="preview">{% if (file.thumbnail_url) { %}
- <a href="{%=file.url%}" title="{%=file.name%}" rel="gallery" download="{%=file.name%}"><img src="{%=file.thumbnail_url%}"></a>
+ <a href="{%=file.url%}" title="{%=file.name%}" rel="gallery" download="{%=file.name%}"><img src="{%=file.thumbnail_url%}" style="width:260px;height:180px;"></a>
{% } %}</td>
<td class="name">
<a href="{%=file.url%}" title="{%=file.name%}" rel="{%=file.thumbnail_url&&'gallery'%}" download="{%=file.name%}">{%=file.name%}</a>