Hi folks
I am developing a new spree store for a client who only has about 15 products currently so I just need to get them in without having to do it through the UI every time.
I've been looking at the seeds.rb file in my new store generated by the spree install command.
It seems like the place to do this kind of stuff and then plugging it in using the Rails rakes tasks.
I figured it's safer using the Spree active_record models to import data as I only have maybe 15 or so products and I'll get all the data validation moving forward. I have seen the spree_sample gem which seems to use yaml to get the demo store data in. I was going to use that as the backup plan.
So I'm trying to put a basic record creation line of code in the seeds.rb file:
p = Product.create :name => "Moo", :price => 10.0, :description => "meeeeep"
I run "rake db:bootstrap" and I get this at the end of the output:
rake aborted!
uninitialized constant Product
So then this triggers me to put in all the necessary requires - that's cool. But then I find there's a few transitive dependencies and the model classes also need to be added to the load path for me to get to them:
require 'rubygems'
gem 'spree_core'
directory = '/Users/bensullivan/.rvm/gems/ruby-1.9.3-p125@geometry_active_wear/gems/spree_core-1.1.0'
$LOAD_PATH.unshift(directory) unless $LOAD_PATH.include?(directory)
require 'active_record'
require 'active_support/core_ext/module/attribute_accessors'
require 'spree/core/delegate_belongs_to'
require 'app/models/spree/variant'
require 'app/models/spree/product'
p = Product.create :name => "Moo", :price => 10.0, :description => "meeeeep"
I get the same error when I retry the db:bootstrap. I don't get the loading error I see through rake when I run this script in isolation (instead I get an error around the database not running which makes more sense cos it isn't). I seem to have to go through a lot of hoop jumping to just create a Product using a spree Model. Which makes me think either I'm doing it wrong or if the API isn't making it easy for me to do then I maybe I shouldn't be doing it at all.
I feel like I'm missing something here - I'm sure there's an easier "Railsy" way to do this.
Anyone got any pointers?
Cheers
Ben