Newer
Older
# licensed under the Affero General Public License version 3. See
# the COPYRIGHT file.
Daniel Vincent Grippi
a validé
before_filter :authenticate_user!
respond_to :html
respond_to :json, :only => :show
album = Album.find_by_id params[:album_id]
Daniel Vincent Grippi
a validé
######################## dealing with local files #############
# get file name
file_name = params[:qqfile]
# get file content type
att_content_type = (request.content_type.to_s == "") ? "application/octet-stream" : request.content_type.to_s
# create temporal file
begin
file = Tempfile.new(file_name, {:encoding => 'BINARY'})
file.print request.raw_post.force_encoding('BINARY')
rescue RuntimeError => e
raise e unless e.message.include?('cannot generate tempfile')
file = Tempfile.new(file_name) # Ruby 1.8 compatibility
file.print request.raw_post
end
Daniel Vincent Grippi
a validé
# put data into this file from raw post request
# create several required methods for this temporal file
Tempfile.send(:define_method, "content_type") {return att_content_type}
Tempfile.send(:define_method, "original_filename") {return file_name}
##############
data = clean_hash(params)
@photo = current_user.post(:photo, data)
Daniel Vincent Grippi
a validé
respond_to do |format|
format.json{render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )}
end
message = I18n.t 'photos.create.type_error'
respond_with :location => album, :error => message
rescue CarrierWave::IntegrityError
message = I18n.t 'photos.create.integrity_error'
respond_with :location => album, :error => message
rescue RuntimeError => e
message = I18n.t 'photos.create.runtime_error'
respond_with :location => album, :error => message
raise e
@album = current_user.album_by_id(params[:album_id])
@photo = current_user.find_visible_post_by_id params[:id]
flash[:notice] = I18n.t 'photos.destroy.notice'
respond_with :location => @photo.album
@photo = current_user.find_visible_post_by_id params[:id]
respond_with @photo, @album
def edit
@photo = current_user.find_visible_post_by_id params[:id]
@album = @photo.album
redirect_to @photo unless current_user.owns? @album
end
def update
@photo = current_user.find_visible_post_by_id params[:id]
data = clean_hash(params)
flash[:notice] = I18n.t 'photos.update.notice'
flash[:error] = I18n.t 'photos.update.error'
private
def clean_hash(params)
if params[:photo]
return {
:photo => {
:caption => params[:photo][:caption],
}
}
else
return{
:album_id => params[:album_id],
:user_file => params[:user_file]
}
end