0

This is how it is:

class Prijave < ActiveRecord::Base
   belongs_to :timovi
   belongs_to :liga
end

class Timovi < ActiveRecord::Base
    belongs_to :sportovi
    has_many :timoviusers, :dependent => :destroy
    has_many :prijaves, :dependent => :destroy
end

When I tried to delete one Timovi I got: uninitialized constant Timovi::Prijafe

also, in console

1.9.3p194 :001 > a=Timovi.find(6)
  Timovi Load (0.2ms)  SELECT `timovis`.* FROM `timovis` WHERE `timovis`.`id` = 6 LIMIT 1
1.9.3p194 :007 > a.prijaves
NameError: uninitialized constant Timovi::Prijafe

Prijafes? I didnt declare that anywhere...I dont have that anywhere... Bug? Have I done something wrong? Thank you

user899119
  • 549
  • 1
  • 11
  • 25
  • Maybe check the name of the model file. Is it maybe named Prijafe.rb Although i really don't think it would be that. And check your migrations also. – Zippie Mar 17 '13 at 22:43
  • nope...it is prijave.rb...I am suspecting something about pluralization... – user899119 Mar 17 '13 at 22:45
  • 1
    A very non railish way, but if your using Linux, go to the root of your aplication and write: `grep -r "prijafe" .` or `grep -r "Prijafe" .` That should write you where that name is occuring. Don't forget the dot at the end – Zippie Mar 17 '13 at 22:47

2 Answers2

2

Active Record uses the active support inflector to work out what the class name should be from the plural form. This isn't foolproof, especially when the word doesn't appear to be English.

You can either add inflector rules to teach rails the plurals/singulars you want to use (there should be an example file in initializers that shows how to do this) or you can specify the :class_name option to has_many so that active record doesn't have to guess the class name.

Frederick Cheung
  • 83,189
  • 8
  • 152
  • 174
1

The plural for "Prijafe" is "Prijaves"

So when you call a.prijaves, you get unitialized constant.

Here's a link: Ruby on Rails: How do you explicitly define plural names and singular names in Rails?

Community
  • 1
  • 1
Monis
  • 47
  • 3
  • yea..it was that ActiveSupport::Inflector.inflections do |inflect| inflect.irregular 'Prijave', 'Prijaves' end – user899119 Mar 17 '13 at 22:51