posts: display validation warnings in flash notice.
This commit is contained in:
@@ -110,6 +110,10 @@ private
|
|||||||
def respond_with_post_after_update(post)
|
def respond_with_post_after_update(post)
|
||||||
respond_with(post) do |format|
|
respond_with(post) do |format|
|
||||||
format.html do
|
format.html do
|
||||||
|
if post.warnings.any?
|
||||||
|
flash[:notice] = post.warnings.full_messages.join(".\n \n")
|
||||||
|
end
|
||||||
|
|
||||||
if post.errors.any?
|
if post.errors.any?
|
||||||
@error_message = post.errors.full_messages.join("; ")
|
@error_message = post.errors.full_messages.join("; ")
|
||||||
render :template => "static/error", :status => 500
|
render :template => "static/error", :status => 500
|
||||||
|
|||||||
@@ -53,7 +53,12 @@ class UploadsController < ApplicationController
|
|||||||
|
|
||||||
def create
|
def create
|
||||||
@upload = Upload.create(params[:upload].merge(:server => Socket.gethostname))
|
@upload = Upload.create(params[:upload].merge(:server => Socket.gethostname))
|
||||||
@upload.process! if @upload.errors.empty?
|
|
||||||
|
if @upload.errors.empty?
|
||||||
|
post = @upload.process!
|
||||||
|
flash[:notice] = post.warnings.full_messages.join(".\n \n") if post.present? && post.warnings.any?
|
||||||
|
end
|
||||||
|
|
||||||
save_recent_tags
|
save_recent_tags
|
||||||
respond_with(@upload)
|
respond_with(@upload)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -43,5 +43,9 @@ class ApplicationRecord < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def warnings
|
||||||
|
@warnings ||= ActiveModel::Errors.new(self)
|
||||||
|
end
|
||||||
|
|
||||||
include ApiMethods
|
include ApiMethods
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -148,6 +148,8 @@ class Upload < ApplicationRecord
|
|||||||
else
|
else
|
||||||
update_attribute(:status, "error: " + post.errors.full_messages.join(", "))
|
update_attribute(:status, "error: " + post.errors.full_messages.join(", "))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
post
|
||||||
end
|
end
|
||||||
|
|
||||||
def process!(force = false)
|
def process!(force = false)
|
||||||
@@ -155,7 +157,7 @@ class Upload < ApplicationRecord
|
|||||||
return if !force && status =~ /processing|completed|error/
|
return if !force && status =~ /processing|completed|error/
|
||||||
|
|
||||||
process_upload
|
process_upload
|
||||||
create_post_from_upload
|
post = create_post_from_upload
|
||||||
|
|
||||||
rescue Timeout::Error, Net::HTTP::Persistent::Error => x
|
rescue Timeout::Error, Net::HTTP::Persistent::Error => x
|
||||||
if @tries > 3
|
if @tries > 3
|
||||||
@@ -164,9 +166,11 @@ class Upload < ApplicationRecord
|
|||||||
@tries += 1
|
@tries += 1
|
||||||
retry
|
retry
|
||||||
end
|
end
|
||||||
|
nil
|
||||||
|
|
||||||
rescue Exception => x
|
rescue Exception => x
|
||||||
update_attributes(:status => "error: #{x.class} - #{x.message}", :backtrace => x.backtrace.join("\n"))
|
update_attributes(:status => "error: #{x.class} - #{x.message}", :backtrace => x.backtrace.join("\n"))
|
||||||
|
nil
|
||||||
|
|
||||||
ensure
|
ensure
|
||||||
delete_temp_file
|
delete_temp_file
|
||||||
|
|||||||
@@ -112,7 +112,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div class="ui-corner-all ui-state-highlight" id="notice" style="<%= "display: none;" unless flash[:notice] %>">
|
<div class="ui-corner-all ui-state-highlight" id="notice" style="<%= "display: none;" unless flash[:notice] %>">
|
||||||
<span><%= flash[:notice] %></span>
|
<span><%= format_text(flash[:notice], inline: true) %>.</span>
|
||||||
<a href="#" id="close-notice-link">close</a>
|
<a href="#" id="close-notice-link">close</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user