I’d like to have read-only access to model’s attributes (:test) that is related to another model (:query) by a has_many association.
I can get the associated :test object to save when I create and associate a new :query, but I can’t work with that associated :test’s attributes in a `before_create’ method.
From what I’m reading in the API documentation I should be able to use the association method (@test = @query.test.whatever) to use the “whatever” attribute, but I am getting the following error when I try to run that code: private method 'test' called for nil:NilClass.
:query is related to :test in a belongs_to relationship…
I’ve tried @test = @query.test.build to instantiate the test object in my method, but that does not work either.
You simply got a name collision. Every object in Ruby has its private method
test.