I''ve run into what I suspect is a total newbie error. Any help appreciated! I have a mysql db table called "content". I created a model rb class called app/models/content.rb class Content < ActiveRecord::Base end I setup a controller file like this: class NewsController < ApplicationController def index @article=Content.find(:all) end end And I have a simple index view file, views/index.rhtml I hit the url: http://localhost:3000/news/index/ and I get this meaningless error: /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:493:in `const_missing'' app/controllers/news_controller.rb:3:in `index'' My config/database.yml is set to point to my local mysql db. Ruby version 1.8.6 (i686-darwin8.11.1) RubyGems version 1.3.0 Rails version 2.1.1 Active Record version 2.1.1 Action Pack version 2.1.1 Active Resource version 2.1.1 Action Mailer version 2.1.1 Active Support version 2.1.1 Application root /Users/andrew/dev/ruby/myapps/jazzhouston Environment development Database adapter mysql Database schema version 0 Any ideas? -- 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 -~----------~----~----~----~------~----~------~--~---
On Oct 4, 8:37 pm, Andrew Lienhard <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I''ve run into what I suspect is a total newbie error. Any help > appreciated! > > I have a mysql db table called "content". > > I created a model rb class called app/models/content.rb >for a class called Content, the table name should be contents> class Content < ActiveRecord::Base > end > > I setup a controller file like this: > > class NewsController < ApplicationController > def index > @article=Content.find(:all) > end > end > > And I have a simple index view file, views/index.rhtml > > I hit the url:http://localhost:3000/news/index/ > > and I get this meaningless error: > > /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/de pendencies.rb:493:in > `const_missing'' > app/controllers/news_controller.rb:3:in `index'' >That means that when it got to line 3 in your controller it hit a constant it couldn''t fine (Content by the looks of it). Not sure why, given the information you''ve given. The full error trace might have more info, it could also indicate that something bad happened while loading content.db. If that is the case then running script/console and evaluating just Content should give a more helpful error. Fred> My config/database.yml is set to point to my local mysql db. > > Ruby version 1.8.6 (i686-darwin8.11.1) > RubyGems version 1.3.0 > Rails version 2.1.1 > Active Record version 2.1.1 > Action Pack version 2.1.1 > Active Resource version 2.1.1 > Action Mailer version 2.1.1 > Active Support version 2.1.1 > Application root /Users/andrew/dev/ruby/myapps/jazzhouston > Environment development > Database adapter mysql > Database schema version 0 > > Any ideas? > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> for a class called Content, the table name should be contentsThanks -- I just found the details on how to handle that: class Content < ActiveRecord::Base set_table_name "content" set_primary_key "content_id" end (Note: Do I need to bounce the server (I did) anytime a model change happens?) My database.yml looks like this: development: adapter: mysql database: mydb username: myuser password: mypass host: localhost And the same for test and production Running the console gives this: MacBook-Pro:~/dev/ruby/myapps/jazzhouston$ script/console Loading development environment (Rails 2.1.1) Consol>> Content NameError: uninitialized constant Content from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:279:in `load_missing_constant'' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:468:in `const_missing'' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:480:in `const_missing'' from (irb):1>>Any ideas? Thanks! -- 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 -~----------~----~----~----~------~----~------~--~---
Well every mistake teaches you something, and I definitely learned a bit about RoR today! The problem? A typo! I had my model file named content.db instead of content.rb I found this by debugging inside of lib/active_support/dependencies.rb Duh. Thanks again. -- 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 -~----------~----~----~----~------~----~------~--~---