changeset 1395:0e4c6c2f400e biblio_alt_search_auth

Fixed teh way the model is accessing the virtual attributes.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Sat, 28 Sep 2013 16:04:04 +0100
parents 0f918e37e1d6
children 5b65c47087b9
files plugins/redmine_bibliography/app/models/authorship.rb
diffstat 1 files changed, 20 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/redmine_bibliography/app/models/authorship.rb	Fri Sep 27 18:43:29 2013 +0100
+++ b/plugins/redmine_bibliography/app/models/authorship.rb	Sat Sep 28 16:04:04 2013 +0100
@@ -9,13 +9,13 @@
 
   validates_presence_of :name_on_paper
 
-  attr_writer :search_author_id, :search_author_class
+  attr_writer :search_author_id , :search_author_class
   attr_writer :search_author_tie
 
   ### attr_accessor :search_results, :identify_author
   ## attr_writer :search_author_class
 
-  before_create :set_author
+  before_save :set_author
   before_update :delete_publication_cache
 
   # tod: review scope of ordering
@@ -44,17 +44,23 @@
     # using default setter (attr_writer)
 
     if self.author.nil?
-      return ""
+      @search_author_class = ""
     else
-      return "Author"
+      @search_author_class = "Author"
     end
+
+    @search_author_class
   end
 
+  # def search_author_class=(search_author_class)
+  #  @search_author_class = search_author_class
+  # end
+
   def search_author_id
     if self.author.nil?
-      return ""
+      "xxx"
     else
-      return self.author_id
+      author_id
     end
   end
 
@@ -87,6 +93,8 @@
     Rails.cache.delete "publication-#{publication.id}-bibtex"
   end
 
+  private
+
   def set_author
     # if an author, simply associates with it
     # if an user, checks if it has already an author associated with it
@@ -95,11 +103,11 @@
 
     logger.error { "%%%%%%%%%%%%%%% Associate Author User %%%%%%%%%%%%%%" }
 
-    logger.error { "EU #{self.to_yaml}" }
-    logger.error { "Class: #{search_author_class}" }
-    logger.error { "ID #{search_author_id}" }
+    logger.error { "Me #{self.to_yaml}" }
+    logger.error { "Class: #{@search_author_class}" }
+    logger.error { "ID #{@search_author_id}" }
 
-    case self.search_author_class
+    case @search_author_class
     when ""
       logger.debug { "Adding new author to the database." }
       author = Author.new
@@ -107,7 +115,7 @@
 
     when "User"
       # get user id
-      user = User.find(self.search_author_id)
+      user = User.find(@search_author_id)
       logger.error { "Found user with this ID: #{user.id}" }
 
       if user.author.nil?
@@ -124,7 +132,7 @@
       end
 
     when "Author"
-      author = Author.find(self.search_author_id)
+      author = Author.find(@search_author_id)
     end
 
     self.author = author