# HG changeset patch # User luisf # Date 1311607986 -3600 # Node ID ce1614b19759f8cd0fb7d70a2aa6c5d62dbfe66e # Parent 4fc8e79dc0eead4023f0e099bf1f531f40fa0bac creates the association between authorship/author/user when saving a publication. diff -r 4fc8e79dc0ee -r ce1614b19759 vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb --- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Mon Jul 25 15:20:01 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Mon Jul 25 16:33:06 2011 +0100 @@ -21,14 +21,16 @@ def create @publication = Publication.new(params[:publication]) + + logger.error { "PUBLICATION CREATE ACTION" } + logger.error { params[:publication] } + + @project = Project.find(params[:project_id]) logger.error { "PARAMS publication" } logger.error { params[:publication] } - - # array with the user ids - @users = [] - + @publication.projects << @project if @publication.save diff -r 4fc8e79dc0ee -r ce1614b19759 vendor/plugins/redmine_bibliography/app/models/authorship.rb --- a/vendor/plugins/redmine_bibliography/app/models/authorship.rb Mon Jul 25 15:20:01 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/models/authorship.rb Mon Jul 25 16:33:06 2011 +0100 @@ -5,13 +5,23 @@ accepts_nested_attributes_for :author accepts_nested_attributes_for :publication + # setter and getter for virtual attribute :user_id def user_id end - def user_id=(uid) - if User.find(uid).author.nil? - User.find(uid).author = Author.new :name => User.find(uid).name + def user_id=(uid) + unless uid.blank? + user = User.find(uid) + if user.author.nil? + # TODO: should reflect the name_on_paper parameter + author = Author.new :name => user.name + author.save! + user.author = author + user.save! + end + + self.author_id = user.author.id end end end