This commit is contained in:
Andreas Stephanides
2013-08-22 12:08:57 +02:00
4 changed files with 20 additions and 11 deletions

View File

@@ -48,8 +48,12 @@ class FotosController < ApplicationController
respond_to do |format| respond_to do |format|
@foto.title = @foto.datei @foto.title = @foto.datei
if @foto.save if @foto.save
format.html { redirect_to gallery_foto_path(@foto.gallery,@foto), notice: 'Foto was successfully created.' } format.html {
format.json { render json: gallery_foto_path(@foto.gallery,@foto), status: :created, location: [@gallery, @foto] } render :json => [@foto.to_jq_upload].to_json,
:content_type => 'text/html',
:layout => false
}
format.json { render json: {files: [@foto.to_jq_upload]}, status: :created, location: [@gallery, @foto] }
else else
format.html { render action: "new" } format.html { render action: "new" }
format.json { render json: @foto.errors, status: :unprocessable_entity } format.json { render json: @foto.errors, status: :unprocessable_entity }
@@ -64,8 +68,12 @@ class FotosController < ApplicationController
respond_to do |format| respond_to do |format|
if @foto.update_attributes(params[:foto]) if @foto.update_attributes(params[:foto])
format.html { redirect_to gallery_foto_path(@foto.gallery,@foto), notice: 'Foto was successfully updated.' } format.html {
format.json { head :no_content } render :json => [@foto.to_jq_upload].to_json,
:content_type => 'text/html',
:layout => false
}
format.json { render json: {files: [@foto.to_jq_upload]}, status: :created, location: [@gallery, @foto] }
else else
format.html { render action: "edit" } format.html { render action: "edit" }
format.json { render json: @foto.errors, status: :unprocessable_entity } format.json { render json: @foto.errors, status: :unprocessable_entity }

View File

@@ -8,11 +8,10 @@ class Foto < ActiveRecord::Base
"id" => read_attribute(:id), "id" => read_attribute(:id),
"title" => read_attribute(:title), "title" => read_attribute(:title),
"description" => read_attribute(:desc), "description" => read_attribute(:desc),
"name" => read_attribute(:file), "name" => read_attribute(:datei),
"size" => file.size, "size" => datei.size,
"url" => file.url, "url" => datei.url,
"thumbnail_url" => file.thumb.url, "thumbnail_url" => datei.thumb.url,
"delete_url" => foto_path(:id => id),
"delete_type" => "DELETE" "delete_type" => "DELETE"
} }
end end

View File

@@ -8,7 +8,7 @@
<span class="btn btn-success fileinput-button"> <span class="btn btn-success fileinput-button">
<i class="icon-plus icon-white"></i> <i class="icon-plus icon-white"></i>
<span>Add files...</span> <span>Add files...</span>
<%= f.file_field :datei %> <%= f.file_field :datei, :multiple=>true%>
<%= f.input :gallery %> <%= f.input :gallery %>
</span> </span>
<button type="submit" class="btn btn-primary start"> <button type="submit" class="btn btn-primary start">
@@ -132,6 +132,8 @@
template.addClass('in'); template.addClass('in');
$('#loading').remove(); $('#loading').remove();
}); });
$('#foto_datei').attr('name', 'foto[datei]');
$('#foto_datei').fileupload();
}); });
</script> </script>

View File

@@ -2,4 +2,4 @@
<%= render 'form_bulk' %> <%= render 'form_bulk' %>
<%= link_to 'Back', gallery_fotos_path(params[:gallery_id]) %> <%= link_to 'Back', gallery_path(params[:gallery_id]) %>