I have two classes, PSA and ZIP and the are related by PSAZIP by has_many: & :through.
I am having errors thrown with the following in each class:
psa.rb (genereated by rails g scaffold PSA)
class Psa < ActiveRecord::Base
has_many :psazips
has_many :zips, :through => psazips
end
psazip.rb (genereated by rails g scaffold PSAZIP)
class Psazip < ActiveRecord::Base
belongs_to :psa
belongs_to :zip
end
zip.rb (genereated by rails g scaffold ZIP)
class Zip < ActiveRecord::Base
has_many:psazips
has_many:psas, :through => :psazips
end
What is the syntax and case grammar for when both Classes are entirely Uppercase? When I have two other class relationships (PSA and State, the rb file name is psa_state.rb).
Do I have to rename the psazip.rb to psa_zip.rb? if so, where else do I need to make the change?
What you have should work as is.
Rails will convert any class name written in camel case to lowercase/underscore form for file names. It thinks
PSAZIPis just one word. It doesn’t see it as camel case, so it generatespsazipinstead ofpsa_zip. Had you usedPsaZiporPSAZip, it would have generatedpsa_zip.But, everything should work as you have it, so long as you consistenly use the class name
Psazip.