29 May 2013

Generating multiple RefineryCMS engines in the same engine

My cheatsheets are -- in reality -- my medium-term memory banks. I'm a lazy programmer and don't like figuring out the same thing twice. so... This is an evolving/developing post .. but I use these cheatsheets too while I'm in development. Sometimes Brute Force involves lots of trial & error to get something right!
$ rails new kikapu -m http://www.refinerycms.com/t/edge
$ echo "rvm 1.9.3@kikapu" > kikapu/.rvmrc
$ vim kikapu/Gemfile

~ add:
  gem  'thin'
  gem  'rack'
~ ZZ (save & exit vim)


$ cd kikapu
$ bundle install
$ rails server
$ rails generate refinery:engine store name:string meta_keywords:string description:text
$ bundle install
$ rails g refinery:stores
$ rake db:migrate
$ rails server

$ rails g refinery:engine product store:references name:string code:string description:text date_available:datetime price:float size_width:float size_height:float size_depth:float weight:float tax_type:references digital_download:references main_pic:references inactive:boolean --engine stores

$ rails g refinery:engine order order_number:integer order_customer:references order_status:string order_notes:text shipping_type:references shipped_on:datetime product_total:float shipping_charges:float tax_charges:float cc_last4:string cc_card_type:string cc_expiry_month:integer cc_expiry_year:integer cc_token:string cc_purchased_on:datetime --engine stores

$ rails g refinery:engine line_item order:references product:references quantity:integer unit_price:float --engine stores --skip-frontend

$ rails g refinery:engine address customer:references order:references is_billing:boolean first_name last_name phone email address1 address2 city state zip country --engine stores --skip-frontend

$ rails g refinery:stores
$ rake db:migrate
$ rails server

During the course of generating engines within the existing engine, you'll need to respond "n" (no) to the following:
  Overwrite ~~/engines/stores/Rakefile? (enter "h" for help) [Ynaqdh] n
  Overwrite ~~/engines/stores/db/seeds.rb? (enter "h" for help) [Ynaqdh] n
  Overwrite ~~/engines/stores/lib/generators/refinery/stores_generator.rb? (enter "h" for help) [Ynaqdh] n
  Overwrite ~~/engines/stores/refinerycms-stores.gemspec? (enter "h" for help) [Ynaqdh] n

I don't want products to appear in dashboard tab; so:
$ vim lib/refinery/products/engine.rb
#         Refinery::Plugin.register do |plugin|
#           plugin.name = "products"
#           plugin.url = {
#             :controller => 'refinery/products/admin/products',
#             :action => 'index'
#           }
#           plugin.pathname = root

#           plugin.activity = {
#             :class_name => :'refinery/products/product',
#             :title => 'name'
#           }
#           
#      end

add more engines
$ rails g refinery:engine order order_number:integer order_user:references order_status:string order_notes:text shipping_type:references  shipped_on:datetime product_cost:float shipping_cost:float tax_cost:float   --engine stores
seeds

When you add additional engines to an existing engine, you may or may not need to have additional lines added to db/seeds.rb. If you want to have a Page seeded for viewing by front-end users, then you'll need an entry in db/seeds.rb (see below). This needs to be manually added in since we had to skip that step during engine generation (because it would have overwritten db/seeds.rb).
Refinery::Orders::Engine.load_seed

No comments:

Post a Comment