Define autofill attributes when creating new supplier from shared_supplier.

This commit is contained in:
Benjamin Meichsner 2013-06-09 18:02:47 +02:00
parent e74c6b4068
commit 7c4ee01ff2
2 changed files with 8 additions and 2 deletions

View file

@ -18,7 +18,7 @@ class SuppliersController < ApplicationController
def new
if params[:shared_supplier_id]
shared_supplier = SharedSupplier.find(params[:shared_supplier_id])
@supplier = shared_supplier.build_supplier(shared_supplier.attributes)
@supplier = shared_supplier.build_supplier(shared_supplier.autofill_attributes)
else
@supplier = Supplier.new
end

View file

@ -8,5 +8,11 @@ class SharedSupplier < ActiveRecord::Base
has_one :supplier
has_many :shared_articles, :foreign_key => :supplier_id
# These set of attributes are used to autofill attributes of new supplier,
# when created by import from shared supplier feature.
def autofill_attributes
whitelist = %w(name address phone fax email url delivery_days note)
attributes.select { |k,_v| whitelist.include?(k) }
end
end