设置:
1.Gemfile
gem 'erp_agreements', :path => '../compass_agile_enterprise/erp_agreements'
gem 'erp_txns_and_accts', :path => '../compass_agile_enterprise/erp_txns_and_accts'
gem 'erp_commerce', :path => '../compass_agile_enterprise/erp_commerce'
gem 'erp_products', :path => '../compass_agile_enterprise/erp_products'
gem 'erp_orders', :path => '../compass_agile_enterprise/erp_orders'
gem 'erp_inventory', :path => '../compass_agile_enterprise/erp_inventory'
2.routes.rb
mount ErpProducts::Engine => '/erp_products'
3.RailsDBAdmin
Tables: applications => Production Manager
运行:
1.ActionController::RoutingError (No route matches [POST] "/erp_products/erp_app/desktop/product_manager/new"):
处理:routes.rb需设置
mount ErpProducts::Engine => '/erp_products'
2.NameError (uninitialized constant ErpProducts::ErpApp::Desktop::ProductManager::BaseController::InventoryEntry):
处理:Gemfile需设置
gem 'erp_inventory', :path => '../compass_agile_enterprise/erp_inventory'
3.NoMethodError (undefined method `number_available' for nil:NilClass):
处理:inventory_entries 和 product_type 必须有一对一的数据。
4.NoMethodError (undefined method `url' for #<Image:0xb793ac8>):
处理:无ProductType.all.collect.images.first.url (table:file_assets无url栏位)
/compass_agile_enterprise/erp_products/app/controllers/erp_products/erp_app/desktop/product_manager/base_controller.rb
def index products = ProductType.all.collect do |product_type| { :id => product_type.id, :title => product_type.description, :imageUrl => product_type.images.empty? ? '/images/img_blank.png' : product_type.images.first.directory+'/'+product_type.images.first.data_file_name, :price => product_type.get_current_simple_amount_with_currency.nil? ? 'no price set' : product_type.get_current_simple_amount_with_currency, :available => product_type.inventory_entries.first.number_available, :sold => product_type.inventory_entries.first.number_sold, :sku => product_type.inventory_entries.first.sku.nil? ? '' : product_type.inventory_entries.first.sku } end render :json => {:products => products} end def images data = {:images => []} product_type = ProductType.find(params[:id]) product_type.images.each do |image| data[:images] << {:id => image.id, :name => image.name, :shortName => image.name, :url => image.directory+'/'+image.data_file_name}#image.url} end render :json => data end
Database 為 Oracle 時遇到的問題處理方法:
1.Index name 'contact_purposes_contacts_index' on table 'contact_purposes_contacts' is too long; the limit is 30 characters
原因: 索引名稱太長.
修改: 20080805000020_base_erp_services.rb
改前: add_index :contact_purposes_contacts, [:contact_id, :contact_purpose_id], :name => "contact_purposes_contacts_index"
改後: add_index :contact_purposes_contacts, [:contact_id, :contact_purpose_id], :name => "contact_purposes_index"
2.identifier is too long: CREATE TABLE "CURRENCIES" ("ID" NUMBER(38) NOT NULL PRIMARY KEY, "NAME" VARCHAR2(255), "DEFINITION" VARCHAR2(255), "INTERNAL_IDENTIFIER" VARCHAR2(255), "NUMERIC_CODE" VARCHAR2(255), "MAJOR_UNIT_SYMBOL" VARCHAR2(255), "MINOR_UNIT_SYMBOL" VARCHAR2(255), "RATIO_OF_MINOR_UNIT_TO_MAJOR_UNIT" VARCHAR2(255), "POSTFIX_LABEL" VARCHAR2(255), "INTRODUCTION_DATE" DATE, "EXPIRATION_DATE" DATE, "CREATED_AT" DATE, "UPDATED_AT" DATE)
原因: 資料表欄位:ratio_of_minor_unit_to_major_unit 太長
修改: 20080805000020_base_erp_services.rb
改前: t.string :ratio_of_minor_unit_to_major_unit
改後: t.string :ratio_of_minor_unit
3.OCIError: ORA-02327: cannot create index on expression with datatype LOB: CREATE INDEX "INDEX_NOTES_ON_CONTENT" ON "NOTES" ("CONTENT")
原因: LOB類型欄位不能建索引.
修改: 20080805000020_base_erp_services.rb
取消: add_index :notes, :content
4.OCIError: ORA-00972: identifier is too long: CREATE TABLE "PREFERENCE_OPTIONS_PREFERENCE_TYPES" ("PREFERENCE_TYPE_ID" NUMBER(38), "PREFERENCE_OPTION_ID" NUMBER(38), "CREATED_AT" DATE, "UPDATED_AT" DATE)
原因: 資料表名稱太長
修改: 20080805000096_base_app_framework.rb
改前:
unless table_exists?(:preference_options_preference_types) create_table :preference_options_preference_types, {:id => false} do |t| t.references :preference_type t.references :preference_option t.timestamps end add_index :preference_options_preference_types, :preference_type_id, :name => 'pref_opt_pref_type_pref_type_id_idx' add_index :preference_options_preference_types, :preference_option_id, :name => 'pref_opt_pref_type_pref_opt_id_idx' end
改後:
unless table_exists?(:preference_options_types) create_table :preference_options_types, {:id => false} do |t| t.references :preference_type t.references :preference_option t.timestamps end add_index :preference_options_types, :preference_type_id, :name => 'pref_opt_pref_type_id_idx' add_index :preference_options_types, :preference_option_id, :name => 'pref_opt_pref_opt_id_idx' end
5.OCIError: ORA-00972: identifier is too long: INSERT INTO "PREFERENCE_OPTIONS_PREFERENCE_TYPES" ("PREFERENCE_TYPE_ID", "PREFERENCE_OPTION_ID") VALUES (10002, 10000)
參考: http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-has_and_belongs_to_many
原因: 需指定中間表名稱.
修改: Application-Stack---Suite\erp_app\app\models\preference_option.rb
has_and_belongs_to_many :preference_type, :join_table => 'preference_options_types'
修改: Application-Stack---Suite\erp_app\app\models\preference_type.rb
has_and_belongs_to_many :preference_options, :join_table => 'preference_options_types'