Hello all,
I''m wanting to use Erb in Yaml to create random keys and correct
foreign-key
relationships.
For models :
class Project < ActiveRecord::Base
has_many :Model
end
class Model < ActiveRecord::Base
belongs_to :Project
end
I have added this to the top of my test_helper.rb :
class Object
def rand_id(size)
"%0#{size}d" % rand((''9'' * size).to_i)
end
end
So now in my projects.yaml :
project_1:
project_id: <%=rand_id(5)%>
ProjectName: Whatever
And model.yaml:
model_1:
model_id: <%=rand_id(5)%>
project_id: <%=project(:project_1).project_id%>
ModelName: Whatever
This is not working :
1) Error:
test_option_list_test_yaml(CategoryTest):
Fixture::FormatError: a YAML error occured parsing
C:/ruby/dev/pm/config/../test/fixtures/category.yml. Please note that YAML
must be consistently indented using spaces. Tabs are not allowed. Please
have a look at http://www.yaml.org/faq.html
The exact error was:
NoMethodError: undefined method `project'' for #<Object:0x2789258>
Is this actually possible ?
Thanks for your advice!
--
Peter Fitzgibbons
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails