My attempts at building custom rake tasks to pre-load initial data for applications continues, and is another widely reported problem.
I have two models, User and Role both in my app/models directory as you’d expect. I do all standard stuff to set up the environment in rake, there are no structural differences at all in the code.
The rake task use users works fine but for roles I get,
rake aborted! ArgumentError: undefined class/module Role ../lib/taksks/post_migrate_roles.rake:6:in `block (2 levels) in <top (required)>' Tasks: TOP => db:task_prep_roles (See full trace by running task with --trace)
Indicating a potential problem with the YAML file; the only difference being the user yml has,
--- - !ruby/object:User attributes: id: 1
and the roles.yml has
--- - !ruby/object:Role attributes: id: 1
There might be something problems with serialised object at http://alisdair.mcdiarmid.org/2013/02/02/fixing-rails-auto-loading-for-serialized-objects.html but it’s quite deep and I’m including it here as a reminder to check out later.