Save the errors in a table and make it viewable in the ui
This commit is contained in:
parent
ad247f6dce
commit
04fa99b1f8
10 changed files with 79 additions and 7 deletions
|
@ -13,3 +13,8 @@ $(document).ready ->
|
|||
false
|
||||
)
|
||||
|
||||
$(".delete_feed").on("ajax:success", (event, data) ->
|
||||
$(this).parent().remove()
|
||||
false
|
||||
)
|
||||
|
||||
|
|
|
@ -15,6 +15,16 @@ class FeedsController < ApplicationController
|
|||
redirect_to :action => :index, :notice => "Add the feed"
|
||||
end
|
||||
|
||||
def destroy
|
||||
Feed.find(params[:id]).destroy
|
||||
render :nothing => true, :status => :ok
|
||||
end
|
||||
|
||||
def errors
|
||||
@errors = Feed.find(params[:id]).errors
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
def import
|
||||
fh = File.open(Rails.root.join("public", "uploads", params[:importer][:import_file].original_filename))
|
||||
# TODO: Hier gehts weiter
|
||||
|
|
3
app/models/error.rb
Normal file
3
app/models/error.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class Error < ActiveRecord::Base
|
||||
belongs_to :feed
|
||||
end
|
|
@ -1,7 +1,8 @@
|
|||
require "pp"
|
||||
|
||||
class Feed < ActiveRecord::Base
|
||||
has_many :items
|
||||
has_many :items, :dependent => :destroy
|
||||
has_many :errors, :dependent => :destroy
|
||||
|
||||
validates_uniqueness_of :url
|
||||
|
||||
|
@ -20,11 +21,19 @@ class Feed < ActiveRecord::Base
|
|||
end
|
||||
by_url(url).update_attribute(:has_errors, false)
|
||||
rescue Exception => e
|
||||
pp e
|
||||
Error.create!(:feed_id => self.id, :action => :fetch_and_parse,
|
||||
:message => e)
|
||||
end
|
||||
end,
|
||||
:on_failure => lambda do |url, response_code, response_header, response_body|
|
||||
by_url(url).update_attribute(:has_errors, true)
|
||||
Error.create!(:feed_id => self.id, :action => :fetch_and_parse,
|
||||
:message => "
|
||||
url: #{url}
|
||||
response-code: #{response_code}
|
||||
response-header: #{response_header}
|
||||
response-body: #{response_body}
|
||||
")
|
||||
end
|
||||
)
|
||||
end
|
||||
|
@ -36,7 +45,15 @@ class Feed < ActiveRecord::Base
|
|||
end,
|
||||
:on_failure => lambda do |url, response_code, response_header, response_body|
|
||||
if params.first.include?(:force)
|
||||
Feed.create!(:url => url, :has_errors => true)
|
||||
feed = Feed.create!(:url => url, :has_errors => true)
|
||||
|
||||
Error.create!(:feed_id => feed.id, :action => :import,
|
||||
:message => "
|
||||
url: #{url}
|
||||
response-code: #{response_code}
|
||||
response-header: #{response_header}
|
||||
response-body: #{response_body}
|
||||
")
|
||||
end
|
||||
end
|
||||
)
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
<ul id="feed_list">
|
||||
<% @feeds.each do |feed| %>
|
||||
<li><%= link_to feed.title, feed_path(feed), :remote => true, :update => "feed_content" %></li>
|
||||
<li>
|
||||
(<%= link_to "del", feed_path(feed), :remote => true, :method => :delete, :class => "delete_feed button", :confirm => "Delete this feed?" %>,
|
||||
<%= link_to "err", errors_feed_path(feed), :remote => true, :class => "button", :update => "feed_content" %>)
|
||||
<%= link_to feed.title, feed_path(feed), :remote => true, :update => "feed_content" %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</ul>
|
||||
|
|
6
app/views/feeds/errors.html.erb
Normal file
6
app/views/feeds/errors.html.erb
Normal file
|
@ -0,0 +1,6 @@
|
|||
<% @errors.each do |error| %>
|
||||
<div class="error-box">
|
||||
<strong><%= error.type %></strong>
|
||||
<pre><%= error.message %></pre>
|
||||
</div>
|
||||
<% end %>
|
|
@ -14,7 +14,10 @@ FeedFu::Application.routes.draw do
|
|||
# resources :products
|
||||
resources :feeds do
|
||||
collection do
|
||||
get "import"
|
||||
get :import
|
||||
end
|
||||
member do
|
||||
get :errors
|
||||
end
|
||||
end
|
||||
|
||||
|
|
11
db/migrate/20130110200633_create_errors.rb
Normal file
11
db/migrate/20130110200633_create_errors.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
class CreateErrors < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :errors do |t|
|
||||
t.references :feed
|
||||
t.string :action, :default => :undefined
|
||||
t.text :message, :default => "no message"
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
10
db/schema.rb
10
db/schema.rb
|
@ -11,7 +11,15 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20120407180851) do
|
||||
ActiveRecord::Schema.define(:version => 20130110200633) do
|
||||
|
||||
create_table "errors", :force => true do |t|
|
||||
t.integer "feed_id"
|
||||
t.string "action", :default => "undefined"
|
||||
t.text "message", :default => "no message"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "feeds", :force => true do |t|
|
||||
t.string "url"
|
||||
|
|
5
spec/models/errors_spec.rb
Normal file
5
spec/models/errors_spec.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Errors do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Reference in a new issue