Brand new one here :) I''ve looked and googled and searched. There are lots of references to RoR Naming Conventions - I haven''t actually been able to locate the list of these conventions. Is there a single list of conventions? Or are they defined through out the documentation and you pick them up as you go? I''m looking for the Database ones right now. I''ve got 8 text files of exported data that I''m putting into a database and building my first RoR app around this data. How should this table be done in relation to the RoR conventions? CREATE TABLE `makes` ( `code` varchar(4) NOT NULL, `Description` varchar(30) NOT NULL, PRIMARY KEY (`code`) ); CREATE TABLE `years` ( `make_code` varchar(4) NOT NULL, `family` varchar(7) NOT NULL, `vehicleType` varchar(2) NOT NULL, `yearGroup` int(4) NOT NULL, `monthGroup` int(2) NOT NULL, `description` varchar(10) NOT NULL, KEY `make_code` (`make_code`), KEY `family` (`family`), KEY `vehicleType` (`vehicleType`), KEY `yearGroup` (`yearGroup`), KEY `monthGroup` (`monthGroup`) ); Thanks :) --~--~---------~--~----~------------~-------~--~----~ 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 25, 2007, at 9:54 PM, Nicholas Orr wrote:> Brand new one here :) > > I''ve looked and googled and searched. > > There are lots of references to RoR Naming Conventions - I haven''t > actually been able to locate the list of these conventions. > > Is there a single list of conventions? > Or are they defined through out the documentation and you pick them up > as you go? > > I''m looking for the Database ones right now. > > I''ve got 8 text files of exported data that I''m putting into a > database and building my first RoR app around this data. > > How should this table be done in relation to the RoR conventions? > > CREATE TABLE `makes` ( > `code` varchar(4) NOT NULL, > `Description` varchar(30) NOT NULL, > PRIMARY KEY (`code`) > );Use generic ''id'' values as your primary keys. Keep your column names in typical_ruby_variable_style and certainly not with a capital letter to start since that indicates a constant to Ruby.> > CREATE TABLE `years` ( > `make_code` varchar(4) NOT NULL, > `family` varchar(7) NOT NULL, > `vehicleType` varchar(2) NOT NULL, > `yearGroup` int(4) NOT NULL, > `monthGroup` int(2) NOT NULL, > `description` varchar(10) NOT NULL, > KEY `make_code` (`make_code`), > KEY `family` (`family`), > KEY `vehicleType` (`vehicleType`), > KEY `yearGroup` (`yearGroup`), > KEY `monthGroup` (`monthGroup`) > ); > > Thanks :)Your migration for these tables will have something like: create_table :makes do |t| t.column :code, :string, :limit => 4, :null => false t.column :description, :string, :limit => 30, :null => false end add_index :makes, :code create_table :years do |t| t.column :make_code, :string, :limit => 4, :null => false t.column :family, :string, :limit => 7, :null => false t.column :vehicle_type, :string, :limit => 2, :null => false t.column :year_group, :integer, :null => false t.column :month_group, :integer, :null => false t.column :description, :string, :limit => 10, :null => false end add_index :years, :make_code add_index :years, :family add_index :years, :vehicle_type add_index :years, :year_group add_index :years, :month_group You should then also have validations in your models for the size limits, for example: class Make validates_length_of :code, :in => 1..4 validates_length_of :description, :in => 1..30 end See more at: http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/ SchemaStatements.html#M000716 You probably also want to avoid names that are "magic" for ActiveRecord like ''type'', ''id'', ''position'', ''updated_at''. I know that you can find a list of these to avoid. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> > Is there a single list of conventions? > Or are they defined through out the documentation and you pick them up > as you go? >I don''t think there''s an official list, it would in the Rails wiki or dev.rubyonrails.org, something like that, but i did find these http://wiki.rubyonrails.org/rails/pages/TipSheetForBeginners http://areyoubeewhy.com/2007/10/18/ruby-101-naming-conventions http://ruby.about.com/b/a/000066.htm --~--~---------~--~----~------------~-------~--~----~ 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 10/26/07, Rob Biedenharn <Rob-GBZH0y1GwQfnZcttdmLDtcI/UQi/AW5J@public.gmane.org> wrote:> > > On Oct 25, 2007, at 9:54 PM, Nicholas Orr wrote: > > Brand new one here :) > > > > I''ve looked and googled and searched. > > > > There are lots of references to RoR Naming Conventions - I haven''t > > actually been able to locate the list of these conventions. > > > > Is there a single list of conventions? > > Or are they defined through out the documentation and you pick them up > > as you go? > > > > I''m looking for the Database ones right now. > > > > I''ve got 8 text files of exported data that I''m putting into a > > database and building my first RoR app around this data. > > > > How should this table be done in relation to the RoR conventions? > > > > CREATE TABLE `makes` ( > > `code` varchar(4) NOT NULL, > > `Description` varchar(30) NOT NULL, > > PRIMARY KEY (`code`) > > ); > > Use generic ''id'' values as your primary keys. > Keep your column names in typical_ruby_variable_style and certainly > not with a capital letter to start since that indicates a constant to > Ruby. > > > > > CREATE TABLE `years` ( > > `make_code` varchar(4) NOT NULL, > > `family` varchar(7) NOT NULL, > > `vehicleType` varchar(2) NOT NULL, > > `yearGroup` int(4) NOT NULL, > > `monthGroup` int(2) NOT NULL, > > `description` varchar(10) NOT NULL, > > KEY `make_code` (`make_code`), > > KEY `family` (`family`), > > KEY `vehicleType` (`vehicleType`), > > KEY `yearGroup` (`yearGroup`), > > KEY `monthGroup` (`monthGroup`) > > ); > > > > Thanks :) > > Your migration for these tables will have something like: > > create_table :makes do |t| > t.column :code, :string, :limit => 4, :null => false > t.column :description, :string, :limit => 30, :null => false > end > add_index :makes, :code > > create_table :years do |t| > t.column :make_code, :string, :limit => 4, :null => false > t.column :family, :string, :limit => 7, :null => false > t.column :vehicle_type, :string, :limit => 2, :null => false > t.column :year_group, :integer, :null => false > t.column :month_group, :integer, :null => false > t.column :description, :string, :limit => 10, :null => false > end > add_index :years, :make_code > add_index :years, :family > add_index :years, :vehicle_type > add_index :years, :year_group > add_index :years, :month_group > > You should then also have validations in your models for the size > limits, for example: > class Make > validates_length_of :code, :in => 1..4 > validates_length_of :description, :in => 1..30 > end > > See more at: > http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/ > SchemaStatements.html#M000716 > > You probably also want to avoid names that are "magic" for > ActiveRecord like ''type'', ''id'', ''position'', ''updated_at''. I know > that you can find a list of these to avoid. > > -Rob > > Rob Biedenharn http://agileconsultingllc.com > Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org > >Thanks a lot for that Rob. I didn''t make up this data structure. I know it totally doesn''t fit the RoR way, hence why I''m looking for the RoR way so I can adapt it :) I''ve also looked some more and found this list which is helpful :) http://blog.invisible.ch/2006/05/01/ruby-on-rails-reference/ Nick --~--~---------~--~----~------------~-------~--~----~ 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 don''t think there''s an official list, it would in the Rails wiki or > dev.rubyonrails.org, something like that, but i did find these > > http://wiki.rubyonrails.org/rails/pages/TipSheetForBeginners > http://areyoubeewhy.com/2007/10/18/ruby-101-naming-conventions > > http://ruby.about.com/b/a/000066.htm >That''s great, Thanks for that too Gene ;) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Can''t remember where I got this but here we go: Variables/Methods: snake_case Class names: CamelCase Constants: ALL CAPITALS Please someone advice if I''m wrong :) Elle On Oct 26, 3:40 pm, "Nicholas Orr" <nicholas....-MbgUkWN72EBeoWH0uzbU5w@public.gmane.org> wrote:> > I don''t think there''s an official list, it would in the Rails wiki or > > dev.rubyonrails.org, something like that, but i did find these > > >http://wiki.rubyonrails.org/rails/pages/TipSheetForBeginners > >http://areyoubeewhy.com/2007/10/18/ruby-101-naming-conventions > > >http://ruby.about.com/b/a/000066.htm > > That''s great, > > Thanks for that too Gene ;)--~--~---------~--~----~------------~-------~--~----~ 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 10/25/07, Nicholas Orr <nicholas.orr-MbgUkWN72EBeoWH0uzbU5w@public.gmane.org> wrote:> > Brand new one here :) > > I''ve looked and googled and searched. > > There are lots of references to RoR Naming Conventions - I haven''t > actually been able to locate the list of these conventions. > > Is there a single list of conventions? > Or are they defined through out the documentation and you pick them up > as you go? > > I''m looking for the Database ones right now. > > I''ve got 8 text files of exported data that I''m putting into a > database and building my first RoR app around this data. > > How should this table be done in relation to the RoR conventions? > > CREATE TABLE `makes` ( > `code` varchar(4) NOT NULL, > `Description` varchar(30) NOT NULL, > PRIMARY KEY (`code`) > );Unfortunately, since you say later that this is a legacy schema that you aren''t able to change, you are facing more than just naming conventions. ActiveRecord doesn''t have any built-in support for non-integer primary keys. You might google ''ActiveRecord noninteger keys'' to look at what others have done in this case.> CREATE TABLE `years` ( > `make_code` varchar(4) NOT NULL, > `family` varchar(7) NOT NULL, > `vehicleType` varchar(2) NOT NULL, > `yearGroup` int(4) NOT NULL, > `monthGroup` int(2) NOT NULL, > `description` varchar(10) NOT NULL, > KEY `make_code` (`make_code`), > KEY `family` (`family`), > KEY `vehicleType` (`vehicleType`), > KEY `yearGroup` (`yearGroup`), > KEY `monthGroup` (`monthGroup`) > );In this table, it''s not clear (to me anyway) what the primary key is. I think that in MySQL the default primary key would be make_code since it''s the first indexed non-null field. On the other hand, if this table really has a composite primary key, then again, AR doesn''t directly support that, although there is some outside work on supporting CPKs in AR: http://compositekeys.rubyforge.org/ -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.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 25, 9:40 pm, "Nicholas Orr" <nicholas....-MbgUkWN72EBeoWH0uzbU5w@public.gmane.org> wrote:> > I don''t think there''s an official list, it would in the Rails wiki or > > dev.rubyonrails.org, something like that, but i did find these > > >http://wiki.rubyonrails.org/rails/pages/TipSheetForBeginners > >http://areyoubeewhy.com/2007/10/18/ruby-101-naming-conventions > > >http://ruby.about.com/b/a/000066.htm > > That''s great, > > Thanks for that too Gene ;)I finally found it, http://wiki.rubyonrails.com/rails/pages/ReservedWords I think for each model/column/controller/action/view, there''s a couple dozen names you shouldn''t use. Here''s some things that can go wrong: if you name a controller "files": http://www.ruby-forum.com/topic/103619 partial named "flas" http://rubyglasses.blogspot.com/2007/05/random-rails-tip-1.html model named "type" http://www.movesonrails.com/articles/2007/02/23/tip-of-the-day column named "type" http://www.benlog.org/2007/1/16/legacy-rails-beware-of-type-columns --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Attached is a little helper class I used on a project. May come in handy, may not. -- Andrew Stone --~--~---------~--~----~------------~-------~--~----~ 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 10/27/07, Rick DeNatale <rick.denatale-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Unfortunately, since you say later that this is a legacy schema that > you aren''t able to change, you are facing more than just naming > conventions. > > ActiveRecord doesn''t have any built-in support for non-integer primary > keys. You might google ''ActiveRecord noninteger keys'' to look at what > others have done in this case.I''m making a brand new app - I can do whatever the hell I want :) I''m going to have to have an import function, to map old to new which is fine by me. Nick --~--~---------~--~----~------------~-------~--~----~ 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 10/28/07, Nicholas Orr <nicholas.orr-MbgUkWN72EBeoWH0uzbU5w@public.gmane.org> wrote:> On 10/27/07, Rick DeNatale <rick.denatale-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Unfortunately, since you say later that this is a legacy schema that > > you aren''t able to change, you are facing more than just naming > > conventions. > > > > ActiveRecord doesn''t have any built-in support for non-integer primary > > keys. You might google ''ActiveRecord noninteger keys'' to look at what > > others have done in this case. > > I''m making a brand new app - I can do whatever the hell I want :) > I''m going to have to have an import function, to map old to new which is > fine by me.Good, glad you''ve got the freedom. Sometimes, I''m not quite so lucky. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.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 -~----------~----~----~----~------~----~------~--~---