upload beispiele attachments...

This commit is contained in:
Andreas Stephanides
2014-02-20 10:50:03 +01:00
parent f13a59b64e
commit 8897a217d9
16 changed files with 77 additions and 32 deletions

View File

@@ -36,7 +36,7 @@ class AttachmentsController < ApplicationController
end
end
# GET /attachments/1/edit
# GET /attachments/1/edit
def edit
@attachment = Attachment.find(params[:id])
@thema = @attachment.thema
@@ -48,16 +48,17 @@ class AttachmentsController < ApplicationController
@attachment = Attachment.new(params[:attachment])
@thema = Thema.find(params[:thema_id])
@attachment.thema_id = @thema.id
@action="create"
logger.info "#{@attachment.inspect}"
respond_to do |format|
if @attachment.save
format.html { redirect_to @thema, notice: 'Attachment was successfully created.' }
format.json { render json: @thema, status: :created, location: @thema }
format.js { @attachment = Attachment.new }
format.js { }
else
format.html { render action: "new" }
format.json { render json: @attachment.errors, status: :unprocessable_entity }
format.js { render action: "new"}
format.js { render action: "new.js.erb"}
end
end
end
@@ -76,7 +77,7 @@ class AttachmentsController < ApplicationController
else
format.html { render action: "edit" }
format.json { render json: @attachment.errors, status: :unprocessable_entity }
format.js { render action: "new"}
format.js { render action: "new"}
end
end
end

View File

@@ -43,15 +43,29 @@ class BeispieleController < ApplicationController
# POST /beispiele
# POST /beispiele.json
def create
logger.info "Creating Beispiel..."
@lva = Lva.find_by_id(params[:lva_id])
params.delete(:lva_id)
@beispiel = Beispiel.new(params[:beispiel])
@backlink = @beispiel.lva.nil? ? root_url : lva_path(@beispiel.lva)
@beispiel.lva=@lva
logger.info "New Beispiel: #{params.inspect}"
# @backlink = @beispiel.lva.nil? ? root_url : lva_path(@beispiel.lva)
@beispiel.name=@beispiel.beispieldatei.filename
logger.info "New Beispiel: #{@beispiel.attributes.inspect}"
@beispiel.datum=Time.now
respond_to do |format|
@beispiel.name=@beispiel.beispieldatei.to_s.split('/').last
if @beispiel.save
format.html { redirect_to @backlink, notice: 'Beispiel was successfully created.' }
format.json { render json: @beispiel, status: :created, location: @beispiel }
format.html {
render :json => [@beispiel.to_jq_upload].to_json,
:content_type => 'text/html',
:layout => false
}
format.json { render json: {files: [@beispiel.to_jq_upload]}, status: :created, location: [@lva, @beispiel] }
# format.html { redirect_to @backlink, notice: 'Beispiel was successfully created.' }
# format.json { render json: @beispiel, status: :created, location: @beispiel }
else
format.html { render action: "new" }
format.json { render json: @beispiel.errors, status: :unprocessable_entity }

View File

@@ -1,6 +1,8 @@
class HomeController < ApplicationController
def index
@beispiele = Beispiel.last([Beispiel.count, 3].min)
@neuigkeiten = Neuigkeit.recent
end
def dev

View File

@@ -34,6 +34,7 @@ class ThemenController < ApplicationController
respond_to do |format|
format.html # new.html.erb
format.json { render json: @thema }
format.js { render action: "edit" }
end
end