updating beispielupload

This commit is contained in:
Thomas Blazek
2015-01-22 11:19:49 +01:00
parent 0280ebb6a1
commit 6f52496a7a
2 changed files with 38 additions and 25 deletions

View File

@@ -47,16 +47,17 @@ class BeispieleController < ApplicationController
@lva = Lva.find_by_id(params[:lva_id])
params.delete(:lva_id)
@beispiel = Beispiel.new(params[:beispiel])
@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|
respond_to do |format|
unless @lva.nil? || @lva.empty?
@beispiel.lva=@lva
@beispiel.datum=Time.now
if @beispiel.save
format.html {
render :json => [@beispiel.to_jq_upload].to_json,
@@ -70,6 +71,18 @@ class BeispieleController < ApplicationController
format.html { render action: "new" }
format.json { render json: @beispiel.errors, status: :unprocessable_entity }
end
else
if @beispiel.update_attributes(params[:beispiel])
@backlink = Lva.find(@beispiel.lva)
format.html { redirect_to @backlink, notice: 'Beispiel was successfully uploaded.'}
format.json { head :no_content }
else
format.html { render action: "new" }
format.json { render json: @beispiel.errors, status: :unprocessable_entity }
end
end
end
end

View File

@@ -12,7 +12,7 @@
<% end %>
</div>
<div class="span6">
<%= f.input :beispieldatei, :as=>:file, :label => "Neue Datei hochladen:", :value=>@beispiel.beispieldatei.url%>
<%= f.file_field :beispieldatei, :label => "Neue Datei hochladen:"%>
</div>
<%=f.input :datum , :as => :datetimepicker %>
@@ -23,7 +23,9 @@
<%= f.input :desc %>
</div>
<div class="span4">
<%= f.input :lva, :as=>:radio, :collection => Lva.all %>
</div>
<%= f.hidden_field :beispieldatei_cache %>
<%= f.actions do %>
<%= f.action :submit, :as => :input %>
@@ -31,9 +33,7 @@
<% end %>
</div>
<div class="span4">
<%= f.input :lva, :as=>:radio, :collection => Lva.all %>
</div>
</div>