From c194d2545f60550ba5c16f52b59488f46c625fc8 Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Tue, 4 Jun 2013 11:28:25 +0200 Subject: [PATCH 1/2] Allowing SharedSuppliers to have multiple Suppliers. Should fix bennibu#107. --- app/controllers/articles_controller.rb | 2 +- app/models/shared_article.rb | 4 ++-- app/models/shared_supplier.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index 820242d6..e8718a0a 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -213,7 +213,7 @@ class ArticlesController < ApplicationController # fills a form whith values of the selected shared_article def import - @article = SharedArticle.find(params[:shared_article_id]).build_new_article + @article = SharedArticle.find(params[:shared_article_id]).build_new_article(@supplier) render :action => 'new', :layout => false end diff --git a/app/models/shared_article.rb b/app/models/shared_article.rb index 777b7f77..440842ec 100644 --- a/app/models/shared_article.rb +++ b/app/models/shared_article.rb @@ -7,8 +7,8 @@ class SharedArticle < ActiveRecord::Base belongs_to :shared_supplier, :foreign_key => :supplier_id - def build_new_article - shared_supplier.supplier.articles.build( + def build_new_article(supplier) + supplier.articles.build( :name => name, :unit => unit, :note => note, diff --git a/app/models/shared_supplier.rb b/app/models/shared_supplier.rb index fa1e582a..f4bd44df 100644 --- a/app/models/shared_supplier.rb +++ b/app/models/shared_supplier.rb @@ -5,7 +5,7 @@ class SharedSupplier < ActiveRecord::Base # set correct table_name in external DB self.table_name = 'suppliers' - has_one :supplier + has_many :suppliers has_many :shared_articles, :foreign_key => :supplier_id end From 6bdb7b35f0b91ec9bc2b5e5107beef31792331d9 Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Mon, 10 Jun 2013 11:37:59 +0200 Subject: [PATCH 2/2] Showing/allowing multiple suppliers per shared supplier in shared-supplier-listing. --- app/views/suppliers/shared_suppliers.haml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/views/suppliers/shared_suppliers.haml b/app/views/suppliers/shared_suppliers.haml index 2de9234d..0c060582 100644 --- a/app/views/suppliers/shared_suppliers.haml +++ b/app/views/suppliers/shared_suppliers.haml @@ -22,7 +22,9 @@ %td= shared_supplier.note %td= shared_supplier.delivery_days %td - - if shared_supplier.supplier + - if shared_supplier.suppliers %i.icon-ok + = '(' + shared_supplier.suppliers.map{|s| s.name}.join(', ') + ')' + = link_to "abonnieren", new_supplier_path(:shared_supplier_id => shared_supplier), class: 'btn' - else - = link_to "abonnieren", new_supplier_path(:shared_supplier_id => shared_supplier), class: 'btn' \ No newline at end of file + = link_to "abonnieren", new_supplier_path(:shared_supplier_id => shared_supplier), class: 'btn'