I''ve got the Agile Web Development with Rails book that tells me to do migrations different than the what is explained on api.rubyonrails.org under ActiveRecord::Migration What is the "best" or "right" syntax of migrations? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
For those of us who don''t own the book, How does the book tell you to do it? ActiveRecord::Migration on the api.rubyonrails.org seems to be the new syntax, where AWDWR will probably be the older (but not deprecated) syntax. On Tue, May 20, 2008 at 8:30 AM, Dustin <dustin.davis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''ve got the Agile Web Development with Rails book that tells me to do > migrations different than the what is explained on api.rubyonrails.org > under ActiveRecord::Migration > > What is the "best" or "right" syntax of migrations? > > > >-- Appreciated my help? Reccommend me on Working With Rails http://workingwithrails.com/person/11030-ryan-bigg --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sexy migrations is syntactic sugar. It is generally preferred. On May 19, 6:37 pm, "Ryan Bigg (Radar)" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> For those of us who don''t own the book, > > How does the book tell you to do it? > > ActiveRecord::Migration on the api.rubyonrails.org seems to be the new > syntax, where AWDWR will probably be the older (but not deprecated) syntax. > > On Tue, May 20, 2008 at 8:30 AM, Dustin <dustin.da...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I''ve got the Agile Web Development with Rails book that tells me to do > > migrations different than the what is explained on api.rubyonrails.org > > under ActiveRecord::Migration > > > What is the "best" or "right" syntax of migrations? > > -- > Appreciated my help? > Reccommend me on Working With Railshttp://workingwithrails.com/person/11030-ryan-bigg--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Here is an example from the book: class CreateProducts < ActiveRecord::Migration def self.up create_table :products do |t| t.column :title, :string t.column :description, :text t.column :image_url, :string end end def self.down drop_table :products end end On May 19, 5:37 pm, "Ryan Bigg (Radar)" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> For those of us who don''t own the book, > > How does the book tell you to do it? > > ActiveRecord::Migration on the api.rubyonrails.org seems to be the new > syntax, where AWDWR will probably be the older (but not deprecated) syntax. > > On Tue, May 20, 2008 at 8:30 AM, Dustin <dustin.da...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I''ve got the Agile Web Development with Rails book that tells me to do > > migrations different than the what is explained on api.rubyonrails.org > > under ActiveRecord::Migration > > > What is the "best" or "right" syntax of migrations? > > -- > Appreciated my help? > Reccommend me on Working With Railshttp://workingwithrails.com/person/11030-ryan-bigg--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
what are "sexy migrations"? On May 19, 8:31 pm, Student <blog...-gRoFi9f2ETe4oY6Ej3vMAKxOck334EZe@public.gmane.org> wrote:> Sexy migrations is syntactic sugar. It is generally preferred. > > On May 19, 6:37 pm, "Ryan Bigg (Radar)" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > For those of us who don''t own the book, > > > How does the book tell you to do it? > > > ActiveRecord::Migration on the api.rubyonrails.org seems to be the new > > syntax, where AWDWR will probably be the older (but not deprecated) syntax. > > > On Tue, May 20, 2008 at 8:30 AM, Dustin <dustin.da...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I''ve got the Agile Web Development with Rails book that tells me to do > > > migrations different than the what is explained on api.rubyonrails.org > > > under ActiveRecord::Migration > > > > What is the "best" or "right" syntax of migrations? > > > -- > > Appreciated my help? > > Reccommend me on Working With Railshttp://workingwithrails.com/person/11030-ryan-bigg--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Basically, the rails core realized that the ''column'' call was redundant within the context of a table definition so you can now do the following create_table :products do |t| t.column :title, :string t.column :description, :text t.column :image_url, :string end Like this: create_table :products do |t| t.string :title t.text :description t.string :image_url end ..or.. create_table :products do |t| t.string :title, :image_url t.text :description end What I personally find "sexier" is the syntax that makes references to other tables more explicit. For example, if a line_item referred to the product table you used to do this: create_table :line_items do |t| t.column :product_id, :integer end But now... create_table :line_items do |t| t.references :product end And you can have even sexier polymorphic associations create_table :addresses do |t| t.references :addressable, :polymorphic=>true end That gives you :addressable_type and :addressable_id with a syntax that looks remarkably like the one you''ll have in your Address class. On May 20, 11:20 am, Dustin <dustin.da...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> what are "sexy migrations"? > > On May 19, 8:31 pm, Student <blog...-gRoFi9f2ETe4oY6Ej3vMAKxOck334EZe@public.gmane.org> wrote: > > > Sexy migrations is syntactic sugar. It is generally preferred. > > > On May 19, 6:37 pm, "Ryan Bigg (Radar)" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > For those of us who don''t own the book, > > > > How does the book tell you to do it? > > > > ActiveRecord::Migration on the api.rubyonrails.org seems to be the new > > > syntax, where AWDWR will probably be the older (but not deprecated) syntax. > > > > On Tue, May 20, 2008 at 8:30 AM, Dustin <dustin.da...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I''ve got the Agile Web Development with Rails book that tells me to do > > > > migrations different than the what is explained on api.rubyonrails.org > > > > under ActiveRecord::Migration > > > > > What is the "best" or "right" syntax of migrations? > > > > -- > > > Appreciated my help? > > > Reccommend me on Working With Railshttp://workingwithrails.com/person/11030-ryan-bigg--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks AndyV When I try this syntax I get this error: rake aborted! undefined method `integer'' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x421d3e8> I just updated rails to 2.0.2, is there something I''m missing? On May 20, 10:50 am, AndyV <AndyVana...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Basically, the rails core realized that the ''column'' call was > redundant within the context of a table definition so you can now do > the following > > create_table :products do |t| > t.column :title, :string > t.column :description, :text > t.column :image_url, :string > end > > Like this: > > create_table :products do |t| > t.string :title > t.text :description > t.string :image_url > end > > ..or.. > > create_table :products do |t| > t.string :title, :image_url > t.text :description > end > > What I personally find "sexier" is the syntax that makes references to > other tables more explicit. For example, if a line_item referred to > the product table you used to do this: > > create_table :line_items do |t| > t.column :product_id, :integer > end > > But now... > > create_table :line_items do |t| > t.references :product > end > > And you can have even sexier polymorphic associations > > create_table :addresses do |t| > t.references :addressable, :polymorphic=>true > end > > That gives you :addressable_type and :addressable_id with a syntax > that looks remarkably like the one you''ll have in your Address class. > > On May 20, 11:20 am, Dustin <dustin.da...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > what are "sexy migrations"? > > > On May 19, 8:31 pm, Student <blog...-gRoFi9f2ETe4oY6Ej3vMAKxOck334EZe@public.gmane.org> wrote: > > > > Sexy migrations is syntactic sugar. It is generally preferred. > > > > On May 19, 6:37 pm, "Ryan Bigg (Radar)" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > wrote: > > > > > For those of us who don''t own the book, > > > > > How does the book tell you to do it? > > > > > ActiveRecord::Migration on the api.rubyonrails.org seems to be the new > > > > syntax, where AWDWR will probably be the older (but not deprecated) syntax. > > > > > On Tue, May 20, 2008 at 8:30 AM, Dustin <dustin.da...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > I''ve got the Agile Web Development with Rails book that tells me to do > > > > > migrations different than the what is explained on api.rubyonrails.org > > > > > under ActiveRecord::Migration > > > > > > What is the "best" or "right" syntax of migrations? > > > > > -- > > > > Appreciated my help? > > > > Reccommend me on Working With Railshttp://workingwithrails.com/person/11030-ryan-bigg--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
nevermind, I found the answer here: http://www.railsforum.com/viewtopic.php?id=17431 On May 20, 1:35 pm, Dustin <dustin.da...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks AndyV > > When I try this syntax I get this error: > > rake aborted! > undefined method `integer'' for > #<ActiveRecord::ConnectionAdapters::TableDefinition:0x421d3e8> > > I just updated rails to 2.0.2, is there something I''m missing? > > On May 20, 10:50 am, AndyV <AndyVana...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Basically, the rails core realized that the ''column'' call was > > redundant within the context of a table definition so you can now do > > the following > > > create_table :products do |t| > > t.column :title, :string > > t.column :description, :text > > t.column :image_url, :string > > end > > > Like this: > > > create_table :products do |t| > > t.string :title > > t.text :description > > t.string :image_url > > end > > > ..or.. > > > create_table :products do |t| > > t.string :title, :image_url > > t.text :description > > end > > > What I personally find "sexier" is the syntax that makes references to > > other tables more explicit. For example, if a line_item referred to > > the product table you used to do this: > > > create_table :line_items do |t| > > t.column :product_id, :integer > > end > > > But now... > > > create_table :line_items do |t| > > t.references :product > > end > > > And you can have even sexier polymorphic associations > > > create_table :addresses do |t| > > t.references :addressable, :polymorphic=>true > > end > > > That gives you :addressable_type and :addressable_id with a syntax > > that looks remarkably like the one you''ll have in your Address class. > > > On May 20, 11:20 am, Dustin <dustin.da...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > what are "sexy migrations"? > > > > On May 19, 8:31 pm, Student <blog...-gRoFi9f2ETe4oY6Ej3vMAKxOck334EZe@public.gmane.org> wrote: > > > > > Sexy migrations is syntactic sugar. It is generally preferred. > > > > > On May 19, 6:37 pm, "Ryan Bigg (Radar)" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > > wrote: > > > > > > For those of us who don''t own the book, > > > > > > How does the book tell you to do it? > > > > > > ActiveRecord::Migration on the api.rubyonrails.org seems to be the new > > > > > syntax, where AWDWR will probably be the older (but not deprecated) syntax. > > > > > > On Tue, May 20, 2008 at 8:30 AM, Dustin <dustin.da...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > I''ve got the Agile Web Development with Rails book that tells me to do > > > > > > migrations different than the what is explained on api.rubyonrails.org > > > > > > under ActiveRecord::Migration > > > > > > > What is the "best" or "right" syntax of migrations? > > > > > > -- > > > > > Appreciated my help? > > > > > Reccommend me on Working With Railshttp://workingwithrails.com/person/11030-ryan-bigg--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> > what are "sexy migrations"? >Migrations with sexy lace and a single rose clutched between it''s teeth: Instead of your old, tired cellulite ridden migrations: def self.up create_table :posts do |t| t.column :created_at, :datetime t.column :updated_at, :datetime t.column :title, :string t.column :slug, :string t.column :text, :text t.column :user_id, :integer end end Your younger, fresh, sexy migrations: def self.up create_table :posts do |t| t.timestamps t.string :title, :slug t.text :text t.references :user end end *insert mandatory wolf whistle here* -- Appreciated my help? Recommend me on Working With Rails http://workingwithrails.com/person/11030-ryan-bigg --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---