Permalink
Browse files

重複登録禁止

  • Loading branch information...
phelrine committed Mar 28, 2012
1 parent 4d74a4f commit f19a6e7ee168c3cf4d6e36c98690f9437db2bbbe
Showing with 8 additions and 4 deletions.
  1. +8 −4 bibhub.rb
View
@@ -51,8 +51,7 @@ def export_button(user, bibtex)
if login?
@title = "ようこそ #{@user.screen_name} さん!"
- @bibtex = Bibliography.where({creator_id:@user.id})
- .limit(20).map{|e| e.to_bibtex}
+ @bibtex = Bibliography.where({creator_id:@user.id}).map{|e| e.to_bibtex}
@comments = Comment.where({creator_id:@user.id}).limit(20).sort(:created_at.desc)
end
@@ -97,9 +96,14 @@ def export_button(user, bibtex)
bibtex = BibTeX.parse params["bibtex"][:tempfile].read.toutf8
bibtex.each{|e|
- bib = Bibliography::create(:bibtex => e.to_hash)
- bib.creator = @user
+ hash = e.to_hash
+ bib = Bibliography.where("bibtex.title".to_sym => hash[:title]).first
+ unless bib
+ bib = Bibliography.new(:bibtex => e.to_hash)
+ bib.creator = @user
+ end
bib.updater = @user
+ bib.bibtex = hash
bib.save
}

0 comments on commit f19a6e7

Please sign in to comment.