Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bookmark_imports improvements

  • Loading branch information...
commit 4a6868a266adedb1e325b2b2ebb118d34650caee 1 parent 3b8cb51
@remear remear authored
View
27 app/controllers/bookmark_imports_controller.rb
@@ -62,26 +62,36 @@ def convert_all
Bookmark.transaction do
@bookmark_imports.each do |bookmarkimport|
+ logger.debug("BOOKMARK TO IMPORT : #{bookmarkimport.title}")
@bookmark = Bookmark.new(bookmarkimport.attributes)
if @bookmark.save
bookmarkimport.destroy
importcount += 1
+ flash[:notice] = "Made #{importcount} bookmarks live"
+ else
+ logger.debug("///////////// COULDN'T SAVE BOOKMARK")
+ @bookmark.errors.each do |error|
+ logger.debug(error)
+ end
+ logger.debug("////////////")
+ flash[:error] = "Unable to make some bookmarks live"
end
end
end
- flash[:notice] = "Made #{importcount} bookmarks live"
+
redirect_to bookmarks_path
end
def do_import
+ require 'csv'
begin
file = params[:do_import][:file]
rowcount = 0
importcount = 0
BookmarkImport.transaction do
- FasterCSV.parse(file, :row_sep => "\r") do |row|
+ CSV.parse(file, :row_sep => "\r") do |row|
title, url = row
@bookmark_pass = Bookmark.all(:conditions => ["BINARY bookmarks.url = ?", url])
@bookmark_import_pass = BookmarkImport.all(:conditions => ["BINARY bookmark_imports.url = ?", url])
@@ -92,8 +102,8 @@ def do_import
rowcount += 1
end
end
- rescue FasterCSV::MalformedCSVError
- @error = "FasterCSV::MalformedCSVError"
+ rescue CSV::MalformedCSVError
+ @error = "CSV::MalformedCSVError"
render :file => "#{RAILS_ROOT}/public/error.html.erb"
else
flash[:notice] = "Imported #{importcount} of #{rowcount} bookmarks"
@@ -125,6 +135,15 @@ def update
end
end
+ def destroy_all
+ @bookmark_imports = BookmarkImport.find_all_by_user_id(current_user.id)
+ @bookmark_imports.each do |bookmark|
+ bookmark.destroy
+ end
+ flash[:notice] = "Removed all imported bookmarks."
+ redirect_to bookmark_imports_url
+ end
+
def destroy
@bookmark_import = BookmarkImport.find(params[:id])
@bookmark_import.destroy
View
20 app/models/bookmark_import.rb
@@ -1,17 +1,3 @@
-# == Schema Information
-#
-# Table name: bookmark_imports
-#
-# id :integer(4) not null, primary key
-# title :string(255)
-# url :string(255)
-# user_id :integer(4)
-# description :string(255)
-# language_id :integer(4)
-# created_at :datetime
-# updated_at :datetime
-#
-
class BookmarkImport < ActiveRecord::Base
belongs_to :language
belongs_to :user
@@ -19,7 +5,11 @@ class BookmarkImport < ActiveRecord::Base
acts_as_taggable_on :topics, :questions
#attr_accessible :title, :url, :user_id, :description, :language_id
- validates_uniqueness_of :url
+ validate :unique_url
+
+ def unique_url
+ errors.add_to_base 'URL is already bookmarked' if Bookmark.find_by_url(self.url)
+ end
def self.per_page
40
View
0  app/views/bookmark_imports/do_import.html.erb → app/views/bookmark_imports/_do_import.html.erb
File renamed without changes
View
1  config/routes.rb
@@ -26,6 +26,7 @@
#bookmark imports
map.convert_all_bookmarks '/bookmark_imports/convert_all', :controller => 'bookmark_imports', :action => 'convert_all'
map.convert_bookmark '/bookmark_imports/:id/convert', :controller => 'bookmark_imports', :action => 'convert'
+ map.destory_all_bookmark_imports '/bookmark_imports/destroy_all', :controller => 'bookmark_imports', :action => 'destroy_all'
map.import_bookmarks '/bookmarks/import', :controller => 'bookmark_imports', :action => 'import'
map.do_bookmark_import '/bookmark_imports/do_import', :controller => 'bookmark_imports', :action => 'do_import'
map.resources :bookmark_imports
View
6 public/error.html.erb
@@ -1,5 +1,5 @@
<% case @error
- when "FasterCSV::MalformedCSVError"
+ when "CSV::MalformedCSVError"
@notice = "Import Rejected"
@message = "The uploaded file does not appear to be formatted correctly."
when "Stuff"
@@ -17,7 +17,7 @@ end %>
<title>Programmer Reference Bin - <%= @notice %></title>
<%= stylesheet_link_tag 'base' %>
<%= stylesheet_link_tag 'new' %>
- <%= stylesheet_link_tag 'new_nav' %>
+ <%= stylesheet_link_tag 'standard' %>
<%= stylesheet_link_tag 'coderay' %>
<!--[if IE]>
<%= stylesheet_link_tag "ie.css" %>
@@ -70,7 +70,7 @@ end %>
<div id="main" class="clearfix">
<div id="col-nav" style="color:#FFFFFF; background:#333333; width:180px; position:absolute; right:0px; top:20px; height:0px; text-align:left; padding:0 20px 0 20px; clear:both; font-size:10px;">
<ul id="categories">
- <%= render :partial => 'languages/side_nav' %>
+ <%= render :partial => 'languages/lang_nav' %>
</ul>
<% if yield :commands %>
<ul class="block">
Please sign in to comment.
Something went wrong with that request. Please try again.