I created model named "whats_new". $ script/generate model whats_new exists app/models/ exists test/unit/ exists test/fixtures/ create app/models/whats_new.rb create test/unit/whats_new_test.rb create test/fixtures/whats_news.yml exists db/migrate create db/migrate/*****_create_whats_news.rb ----- rake db:migrate WhatsNew.find() WhatsNew.new There are no problem. However, test/unit/whats_new_test.rb ----------------- whats_news(:data1) ----------------- => "No class attached to find." ----------------------------------------------- class Fixtures ... ... def initialize ... @class_name = class_name || (ActiveRecord::Base.pluralize_table_names ? @table_name.singularize.camelize : @table_name.camelize) p @class_name ... end end ----------------------------------------------- => "WhatsNews" A true class name is "WhatsNew". @table_name == "whats_news">> "whats_news".singularize.camelize=> "WhatsNews">> "whats_new".pluralize.singularize=> "whats_news" By the way, I cannot speak English... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> I created model named "whats_new". > > $ script/generate model whats_new > exists app/models/ > exists test/unit/ > exists test/fixtures/ > create app/models/whats_new.rb > create test/unit/whats_new_test.rb > create test/fixtures/whats_news.yml > exists db/migrate > create db/migrate/*****_create_whats_news.rb > > ----- > > rake db:migrate > WhatsNew.find() > WhatsNew.new > > There are no problem. > > However, > test/unit/whats_new_test.rb > ----------------- > whats_news(:data1) > ----------------- > => "No class attached to find." > > ----------------------------------------------- > class Fixtures > ... > ... > def initialize > ... > @class_name = class_name || > (ActiveRecord::Base.pluralize_table_names ? > @table_name.singularize.camelize : @table_name.camelize) > p @class_name > ... > end > end > ----------------------------------------------- > => "WhatsNews" > A true class name is "WhatsNew". > > @table_name == "whats_news" > >>> "whats_news".singularize.camelize > => "WhatsNews" >>> "whats_new".pluralize.singularize > => "whats_news" > > By the way, I cannot speak English...In english, ''news'' is both singular and plural. A single news item is still called ''news'' not ''new''. Two choices for you.. - Add your own inflection so that ''news'' is singularlized to ''news''. - Change your class name. -philip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Philip Hallstrom wrote:> Two choices for you.. > > - Add your own inflection so that ''news'' is singularlized to ''news''. > - Change your class name.Keep in mind that model names should be nouns. Controller actions are verbs. In your case of WhatsNew is practically a complete sentence. "What is new?" Maybe use something like NewsItem or simply News, which rails will properly pluralize as "News." In this case the table name will be news. Then to find out, "What is new?" you can create a named_scope that gets recent new items like this: @recent_news_items = NewsItem.recent or @recent_news_items = News.recent -- 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 -~----------~----~----~----~------~----~------~--~---
Robert Walker wrote:> Keep in mind that model names should be nouns. Controller actions are > verbs. In your case of WhatsNew is practically a complete sentence.Correction: Controller actions aren''t necessarily verbs. It might be more accurate to say the handles what to do with the request and the verb is part of the request (i.e. "GET index" would get then index of news items and "POST create" would create new news items). -- 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 -~----------~----~----~----~------~----~------~--~---
Thank you for everybody. I change the class name. Robert Walker wrote:> @recent_news_items = NewsItem.recent > > or > > @recent_news_items = News.recentIt did not hit on in me. "What is new?" is in "News". P.S. I added rails/lib/rails_generator/generators/components/model/ model_generator.rb to p ''warning: class_name'' unless class_name =class_name.pluralize.singularize --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---