changeset 446:995d4c99843d feature_36

New form saving models correctly. BUG: duplicate authors in authorships table
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Wed, 08 Jun 2011 13:29:40 +0100
parents 77f88379115a
children 565f82b8ff9c
files vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb vendor/plugins/redmine_bibliography/app/models/publication.rb vendor/plugins/redmine_bibliography/app/views/publications/_edit.html.erb vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb
diffstat 4 files changed, 12 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Wed Jun 08 11:35:04 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Wed Jun 08 13:29:40 2011 +0100
@@ -10,6 +10,9 @@
     # we'll always want a new publication to have its bibtex entry
     @publication.build_bibtex_entry
     
+    # and at least one author
+    @publication.authors.build
+    
     # the step we're at in the form
     @publication.current_step = session[:publication_step]
 
--- a/vendor/plugins/redmine_bibliography/app/models/publication.rb	Wed Jun 08 11:35:04 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/publication.rb	Wed Jun 08 13:29:40 2011 +0100
@@ -5,15 +5,14 @@
   
   has_many :authorships
   has_many :authors, :through => :authorships
+  
   has_one :bibtex_entry, :dependent => :destroy
 
   validates_presence_of :title
 
   accepts_nested_attributes_for :authorships
-  accepts_nested_attributes_for :authors, :reject_if => lambda { |a| a[:name].blank? }, :allow_destroy => true
-#  accepts_nested_attributes_for :bibtex_entry, :reject_if => lambda { |a| a[:name].blank? }, :allow_destroy => true 
-  
-  
+  accepts_nested_attributes_for :authors, :allow_destroy => true
+  accepts_nested_attributes_for :bibtex_entry, :allow_destroy => true 
   
   attr_writer :current_step
 
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_edit.html.erb	Wed Jun 08 11:35:04 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_edit.html.erb	Wed Jun 08 13:29:40 2011 +0100
@@ -12,6 +12,9 @@
     </p>
   <%- end -%>
   
+  
+  <h3>Other Details</h3>
+  
   <% f.fields_for :bibtex_entry do |bib| -%>
     <p> 
       <%= bib.label :year, l(:year) %>  <%= bib.text_field :year %>  
--- a/vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb	Wed Jun 08 11:35:04 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb	Wed Jun 08 13:29:40 2011 +0100
@@ -3,9 +3,9 @@
 <%= h @publication.title %>
 
 <h4>Authors</h4>
-<% @publication.authors.each do |author| %>
-<%= h author.name  %> <br />
-<% end %>
+  <% for author in @publication.authors %>
+      <%= h author.name  %> <br />
+  <% end %>
 <br />
 
 <%- if @publication.bibtex_entry != nil -%>