Luiz Vitor Martinez Cardoso
2008-Jul-18 21:51 UTC
Problem with has_many and belongs_to: NameError: uninitialized constant User::Recipy
Hello, I''m learning to use ORM system. I read a lot of content but i can''t get it to work. class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.column :email, :string t.column :nome, :string t.timestamps end end def self.down drop_table :users end end class CreateRecipies < ActiveRecord::Migration def self.up create_table :recipies do |t| t.column :titulo, :string t.column :descricao, :string t.column :user_id, :integer t.column :recipie_id, :integer t.timestamps end end def self.down drop_table :recipies end end class User < ActiveRecord::Base has_many :recipies end class Recipie < ActiveRecord::Base belongs_to :user end At console i''m typing usr = Users.find(1)>> recipie = usr.recipiesNameError: uninitialized constant User::Recipy from /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:492:in `const_missing'' from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1909:in `compute_type'' from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/reflection.rb:129:in `send'' from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/reflection.rb:129:in `klass'' from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/reflection.rb:137:in `quoted_table_name'' from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/has_many_association.rb:84:in `construct_sql'' from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_collection.rb:8:in `initialize'' from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations.rb:1128:in `new'' from /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations.rb:1128:in `recipies'' from (irb):2 Why? Thanks for your attention! -- Regards, Luiz Vitor Martinez Cardoso cel.: (11) 8187-8662 blog: rubz.org engineer student at maua.br --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Eric Hill
2008-Jul-18 22:53 UTC
Re: Problem with has_many and belongs_to: NameError: uninitialized constant User::Recipy
> NameError: uninitialized constant User::RecipyCheck your spelling. -e Luiz Vitor Martinez Cardoso wrote:> Hello, > > I''m learning to use ORM system. I read a lot of content but i can''t get > it to work. > > class CreateUsers < ActiveRecord::Migration > def self.up > create_table :users do |t| > t.column :email, :string > t.column :nome, :string > t.timestamps > end > end > > def self.down > drop_table :users > end > end > > class CreateRecipies < ActiveRecord::Migration > def self.up > create_table :recipies do |t| > t.column :titulo, :string > t.column :descricao, :string > t.column :user_id, :integer > t.column :recipie_id, :integer > t.timestamps > end > end > > def self.down > drop_table :recipies > end > end > > class User < ActiveRecord::Base > has_many :recipies > end > > class Recipie < ActiveRecord::Base > belongs_to :user > end > > At console i''m typing > > usr = Users.find(1) > > >> recipie = usr.recipies > NameError: uninitialized constant User::Recipy > from > /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/dependencies.rb:492:in > `const_missing'' > from > /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1909:in > `compute_type'' > from > /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/reflection.rb:129:in > `send'' > from > /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/reflection.rb:129:in > `klass'' > from > /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/reflection.rb:137:in > `quoted_table_name'' > from > /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/has_many_association.rb:84:in > `construct_sql'' > from > /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations/association_collection.rb:8:in > `initialize'' > from > /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations.rb:1128:in > `new'' > from > /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/associations.rb:1128:in > `recipies'' > from (irb):2 > > > Why? > > Thanks for your attention! > > > -- > Regards, > > Luiz Vitor Martinez Cardoso > cel.: (11) 8187-8662 > blog: rubz.org <http://rubz.org> > engineer student at maua.br <http://maua.br> > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Denner Bizarria
2008-Sep-17 03:20 UTC
Re: Problem with has_many and belongs_to: NameError: uniniti
try this...> class User < ActiveRecord::Base >>> has_many :recipies, :class_name => ''Recipie'' > end > > class Recipie < ActiveRecord::Base > belongs_to :user > end-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---