I am a relative newbie to RoR. How is RoR able to know to look for a table named "people" from a model class "Person"? Is there a look up table of some kind or is this defined in a class? How does RoR handle a model name of "Content"? Would it expect a table name of "contents" or "content"? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rick Olson
2006-Sep-11 00:46 UTC
Re: Nameing Conventions: You say Tomato, I say tomatoes...
On 9/10/06, Tony K. <tony.kruse-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I am a relative newbie to RoR. How is RoR able to know to look for a > table named "people" from a model class "Person"? Is there a look up > table of some kind or is this defined in a class? > > How does RoR handle a model name of "Content"? Would it expect a table > name of "contents" or "content"?There''s a set of inflection rules, but they don''t catch everything. The stock environment.rb file shows you examples to tweak it. Rails handles all the common cases though. If you want to try it out, use script/console ''content''.pluralize ''contents''.singularize -- Rick Olson http://weblog.techno-weenie.net http://mephistoblog.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 -~----------~----~----~----~------~----~------~--~---
Aaron Baldwin
2006-Sep-11 00:48 UTC
Re: Nameing Conventions: You say Tomato, I say tomatoes...
The pluralize function is in the Inflector module: http://api.rubyonrails.com/classes/Inflector.html The pluralization rules are in inflections.rb. Here are the rules used in pluralization from that file: inflect.plural(/$/, ''s'') inflect.plural(/s$/i, ''s'') inflect.plural(/(ax|test)is$/i, ''\1es'') inflect.plural(/(octop|vir)us$/i, ''\1i'') inflect.plural(/(alias|status)$/i, ''\1es'') inflect.plural(/(bu)s$/i, ''\1ses'') inflect.plural(/(buffal|tomat)o$/i, ''\1oes'') inflect.plural(/([ti])um$/i, ''\1a'') inflect.plural(/sis$/i, ''ses'') inflect.plural(/(?:([^f])fe|([lr])f)$/i, ''\1\2ves'') inflect.plural(/(hive)$/i, ''\1s'') inflect.plural(/([^aeiouy]|qu)y$/i, ''\1ies'') inflect.plural(/([^aeiouy]|qu)ies$/i, ''\1y'') inflect.plural(/(x|ch|ss|sh)$/i, ''\1es'') inflect.plural(/(matr|vert|ind)ix|ex$/i, ''\1ices'') inflect.plural(/([m|l])ouse$/i, ''\1ice'') inflect.plural(/^(ox)$/i, ''\1en'') inflect.plural(/(quiz)$/i, ''\1zes'') Aaron On Sep 10, 2006, at 6:07 PM, Tony K. wrote:> > I am a relative newbie to RoR. How is RoR able to know to look for a > table named "people" from a model class "Person"? Is there a look up > table of some kind or is this defined in a class? > > How does RoR handle a model name of "Content"? Would it expect a table > name of "contents" or "content"? > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
kian.hui.teo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Sep-11 07:32 UTC
Re: Nameing Conventions: You say Tomato, I say tomatoes...
I heard some complaints that this works only for the English language, obviously. Is there a way to hack this file to handle other languages, say German ? regards, Kianhui Aaron Baldwin wrote:> The pluralize function is in the Inflector module: > > http://api.rubyonrails.com/classes/Inflector.html > > The pluralization rules are in inflections.rb. Here are the rules > used in pluralization from that file: > > inflect.plural(/$/, ''s'') > inflect.plural(/s$/i, ''s'') > inflect.plural(/(ax|test)is$/i, ''\1es'') > inflect.plural(/(octop|vir)us$/i, ''\1i'') > inflect.plural(/(alias|status)$/i, ''\1es'') > inflect.plural(/(bu)s$/i, ''\1ses'') > inflect.plural(/(buffal|tomat)o$/i, ''\1oes'') > inflect.plural(/([ti])um$/i, ''\1a'') > inflect.plural(/sis$/i, ''ses'') > inflect.plural(/(?:([^f])fe|([lr])f)$/i, ''\1\2ves'') > inflect.plural(/(hive)$/i, ''\1s'') > inflect.plural(/([^aeiouy]|qu)y$/i, ''\1ies'') > inflect.plural(/([^aeiouy]|qu)ies$/i, ''\1y'') > inflect.plural(/(x|ch|ss|sh)$/i, ''\1es'') > inflect.plural(/(matr|vert|ind)ix|ex$/i, ''\1ices'') > inflect.plural(/([m|l])ouse$/i, ''\1ice'') > inflect.plural(/^(ox)$/i, ''\1en'') > inflect.plural(/(quiz)$/i, ''\1zes'') > > Aaron > > On Sep 10, 2006, at 6:07 PM, Tony K. wrote: > > > > > I am a relative newbie to RoR. How is RoR able to know to look for a > > table named "people" from a model class "Person"? Is there a look up > > table of some kind or is this defined in a class? > > > > How does RoR handle a model name of "Content"? Would it expect a table > > name of "contents" or "content"? > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
njmacinnes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Sep-11 10:48 UTC
Re: Nameing Conventions: You say Tomato, I say tomatoes...
Yes, you just have to change it and add your own rules. For example: inflect.plural(/[aeiou]$/i, ''\1en'') The question is: ist es pizzas oder pizzen? -Nathan On 11/09/06, kian.hui.teo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <kian.hui.teo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I heard some complaints that this works only for the English language, > obviously. > Is there a way to hack this file to handle other languages, say German > ? > > regards, > Kianhui > > Aaron Baldwin wrote: > > The pluralize function is in the Inflector module: > > > > http://api.rubyonrails.com/classes/Inflector.html > > > > The pluralization rules are in inflections.rb. Here are the rules > > used in pluralization from that file: > > > > inflect.plural(/$/, ''s'') > > inflect.plural(/s$/i, ''s'') > > inflect.plural(/(ax|test)is$/i, ''\1es'') > > inflect.plural(/(octop|vir)us$/i, ''\1i'') > > inflect.plural(/(alias|status)$/i, ''\1es'') > > inflect.plural(/(bu)s$/i, ''\1ses'') > > inflect.plural(/(buffal|tomat)o$/i, ''\1oes'') > > inflect.plural(/([ti])um$/i, ''\1a'') > > inflect.plural(/sis$/i, ''ses'') > > inflect.plural(/(?:([^f])fe|([lr])f)$/i, ''\1\2ves'') > > inflect.plural(/(hive)$/i, ''\1s'') > > inflect.plural(/([^aeiouy]|qu)y$/i, ''\1ies'') > > inflect.plural(/([^aeiouy]|qu)ies$/i, ''\1y'') > > inflect.plural(/(x|ch|ss|sh)$/i, ''\1es'') > > inflect.plural(/(matr|vert|ind)ix|ex$/i, ''\1ices'') > > inflect.plural(/([m|l])ouse$/i, ''\1ice'') > > inflect.plural(/^(ox)$/i, ''\1en'') > > inflect.plural(/(quiz)$/i, ''\1zes'') > > > > Aaron > > > > On Sep 10, 2006, at 6:07 PM, Tony K. wrote: > > > > > > > > I am a relative newbie to RoR. How is RoR able to know to look for a > > > table named "people" from a model class "Person"? Is there a look up > > > table of some kind or is this defined in a class? > > > > > > How does RoR handle a model name of "Content"? Would it expect a table > > > name of "contents" or "content"? > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
njmacinnes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Sep-11 10:50 UTC
Re: Nameing Conventions: You say Tomato, I say tomatoes...
Oops, that should be: inflect.plural(/([aeiou])$/i, ''\1en'') On 11/09/06, njmacinnes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <njmacinnes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Yes, you just have to change it and add your own rules. For example: > > inflect.plural(/[aeiou]$/i, ''\1en'') > > The question is: ist es pizzas oder pizzen? > > -Nathan > > On 11/09/06, kian.hui.teo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <kian.hui.teo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I heard some complaints that this works only for the English language, > > obviously. > > Is there a way to hack this file to handle other languages, say German > > ? > > > > regards, > > Kianhui > > > > Aaron Baldwin wrote: > > > The pluralize function is in the Inflector module: > > > > > > http://api.rubyonrails.com/classes/Inflector.html > > > > > > The pluralization rules are in inflections.rb. Here are the rules > > > used in pluralization from that file: > > > > > > inflect.plural(/$/, ''s'') > > > inflect.plural(/s$/i, ''s'') > > > inflect.plural(/(ax|test)is$/i, ''\1es'') > > > inflect.plural(/(octop|vir)us$/i, ''\1i'') > > > inflect.plural(/(alias|status)$/i, ''\1es'') > > > inflect.plural(/(bu)s$/i, ''\1ses'') > > > inflect.plural(/(buffal|tomat)o$/i, ''\1oes'') > > > inflect.plural(/([ti])um$/i, ''\1a'') > > > inflect.plural(/sis$/i, ''ses'') > > > inflect.plural(/(?:([^f])fe|([lr])f)$/i, ''\1\2ves'') > > > inflect.plural(/(hive)$/i, ''\1s'') > > > inflect.plural(/([^aeiouy]|qu)y$/i, ''\1ies'') > > > inflect.plural(/([^aeiouy]|qu)ies$/i, ''\1y'') > > > inflect.plural(/(x|ch|ss|sh)$/i, ''\1es'') > > > inflect.plural(/(matr|vert|ind)ix|ex$/i, ''\1ices'') > > > inflect.plural(/([m|l])ouse$/i, ''\1ice'') > > > inflect.plural(/^(ox)$/i, ''\1en'') > > > inflect.plural(/(quiz)$/i, ''\1zes'') > > > > > > Aaron > > > > > > On Sep 10, 2006, at 6:07 PM, Tony K. wrote: > > > > > > > > > > > I am a relative newbie to RoR. How is RoR able to know to look for a > > > > table named "people" from a model class "Person"? Is there a look up > > > > table of some kind or is this defined in a class? > > > > > > > > How does RoR handle a model name of "Content"? Would it expect a table > > > > name of "contents" or "content"? > > > > > > > > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---