Hello, I have this class in my Rails project : class CreateModels < ActiveRecord::Migration def self.up create_table :models do |t| t.string :model, :default => "Model", :limit => 10 t.string :description, :default => "short Description", :limit => 20 t.string :longdescription, :default => "long Description", :limit => 40 t.timestamps end end def self.down drop_table :models end end Now, if I need the same fields in another table, I need to put again : . . t.string :description, :default => "short Description", :limit => 20 t.string :longdescription, :default => "long Description", :limit => 40 . . How can I create something like a "template" or "pattern" that includes for example ":default => "short Description", :limit => 20", then I only use this template to create the new table. Something like this : . . t.Template2 :description, # ''Template2'' includes ":default => "short Description", :limit => 20" t.Template3 :longdescription, # ''Template3'' includes ":default => "long Description", :limit => 40" . . Then I will use this new type to create new fields with the same characteristics in all the tables. Thanks, Jose. --~--~---------~--~----~------------~-------~--~----~ 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 18 Sep 2008, at 09:26, Jose G. wrote:> How can I create something like a "template" or "pattern" that > includes for example ":default => "short Description", :limit => > 20", then I only use this template to create the new table. > Something like this : > > . > . > t.Template2 :description, # ''Template2'' includes ":default => "short > Description", :limit => 20" > t.Template3 :longdescription, # ''Template3'' includes ":default => > "long Description", :limit => 40" > . > . > > Then I will use this new type to create new fields with the same > characteristics in all the tables. >Well you could certainly add methods to the TableDefinition class (which is the class of the objects yielded by the create_table block) if you wanted to. Fred> Thanks, > > Jose. > > >--~--~---------~--~----~------------~-------~--~----~ 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 Fred, If I have : class CreateModels < ActiveRecord::Migration def self.up create_table :models do |t| t.Template1 :model, t.Template2 :description, t.Template3 :longdescription, t.timestamps end end I need to create the method inside "CreateModels" ? or Inside "Models". And then how can I use this "Template" in another "Table definition". Thanks. --- On Thu, 9/18/08, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> From: Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > Subject: [Rails] Re: CUSTOM DATA TYPES > To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > Date: Thursday, September 18, 2008, 4:31 AM > On 18 Sep 2008, at 09:26, Jose G. wrote: > > How can I create something like a "template" > or "pattern" that > > includes for example ":default => "short > Description", :limit => > > 20", then I only use this template to create the > new table. > > Something like this : > > > > . > > . > > t.Template2 :description, # ''Template2'' > includes ":default => "short > > Description", :limit => 20" > > t.Template3 :longdescription, # ''Template3'' > includes ":default => > > "long Description", :limit => 40" > > . > > . > > > > Then I will use this new type to create new fields > with the same > > characteristics in all the tables. > > > Well you could certainly add methods to the TableDefinition > class > (which is the class of the objects yielded by the > create_table block) > if you wanted to. > > Fred > > Thanks, > > > > Jose. > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 18 Sep 2008, at 09:44, Jose G. wrote:> > Thanks Fred, > > If I have : > > class CreateModels < ActiveRecord::Migration > def self.up > create_table :models do |t| > t.Template1 :model, > t.Template2 :description, > t.Template3 :longdescription, > > t.timestamps > end > end > > I need to create the method inside "CreateModels" ? or Inside > "Models". >Neither. I was suggesting extending the TableDefinition (defined in schema_defintion.rb) Fred> And then how can I use this "Template" in another "Table definition". > > Thanks. > > > --- On Thu, 9/18/08, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > >> From: Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> Subject: [Rails] Re: CUSTOM DATA TYPES >> To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >> Date: Thursday, September 18, 2008, 4:31 AM >> On 18 Sep 2008, at 09:26, Jose G. wrote: >>> How can I create something like a "template" >> or "pattern" that >>> includes for example ":default => "short >> Description", :limit => >>> 20", then I only use this template to create the >> new table. >>> Something like this : >>> >>> . >>> . >>> t.Template2 :description, # ''Template2'' >> includes ":default => "short >>> Description", :limit => 20" >>> t.Template3 :longdescription, # ''Template3'' >> includes ":default => >>> "long Description", :limit => 40" >>> . >>> . >>> >>> Then I will use this new type to create new fields >> with the same >>> characteristics in all the tables. >>> >> Well you could certainly add methods to the TableDefinition >> class >> (which is the class of the objects yielded by the >> create_table block) >> if you wanted to. >> >> Fred >>> Thanks, >>> >>> Jose. >>> >>>> >> >> >> > > >--~--~---------~--~----~------------~-------~--~----~ 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 agai Fred, If I change the file in rails directory :> Neither. I was suggesting extending the TableDefinition > (defined in > schema_defintion.rb)Then If I upgrade to another rails version I need to modify the file again ? Exists another way to put it inside the rails application independent from rails upgrade ? Thanks, Jose. --- On Thu, 9/18/08, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> From: Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > Subject: [Rails] Re: CUSTOM DATA TYPES > To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > Date: Thursday, September 18, 2008, 5:45 AM > On 18 Sep 2008, at 09:44, Jose G. wrote: > > > > > Thanks Fred, > > > > If I have : > > > > class CreateModels < ActiveRecord::Migration > > def self.up > > create_table :models do |t| > > t.Template1 :model, > > t.Template2 :description, > > t.Template3 :longdescription, > > > > t.timestamps > > end > > end > > > > I need to create the method inside > "CreateModels" ? or Inside > > "Models". > > > > Neither. I was suggesting extending the TableDefinition > (defined in > schema_defintion.rb) > > Fred > > And then how can I use this "Template" in > another "Table definition". > > > > Thanks. > > > > > > --- On Thu, 9/18/08, Frederick Cheung > <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > >> From: Frederick Cheung > <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >> Subject: [Rails] Re: CUSTOM DATA TYPES > >> To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > >> Date: Thursday, September 18, 2008, 4:31 AM > >> On 18 Sep 2008, at 09:26, Jose G. wrote: > >>> How can I create something like a > "template" > >> or "pattern" that > >>> includes for example ":default => > "short > >> Description", :limit => > >>> 20", then I only use this template to > create the > >> new table. > >>> Something like this : > >>> > >>> . > >>> . > >>> t.Template2 :description, # > ''Template2'' > >> includes ":default => "short > >>> Description", :limit => 20" > >>> t.Template3 :longdescription, # > ''Template3'' > >> includes ":default => > >>> "long Description", :limit => > 40" > >>> . > >>> . > >>> > >>> Then I will use this new type to create new > fields > >> with the same > >>> characteristics in all the tables. > >>> > >> Well you could certainly add methods to the > TableDefinition > >> class > >> (which is the class of the objects yielded by the > >> create_table block) > >> if you wanted to. > >> > >> Fred > >>> Thanks, > >>> > >>> Jose. > >>> > >>>> > >> > >> > >> > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 Sep 18, 7:29 pm, "Jose G." <jgonzal...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> Thanks agai Fred, > > If I change the file in rails directory : > > > Neither. I was suggesting extending the TableDefinition > > (defined in > > schema_defintion.rb)I wouldn''t do that. This is ruby - you can reopen a class whenever you feel like it, eg stick it in a file in lib and require that or (if you''re going to reuse it across apps) make it into a plugin. Fred> > Then If I upgrade to another rails version I need to modify the file again ? > > Exists another way to put it inside the rails application independent from rails upgrade ? > > Thanks, > > Jose. > > --- On Thu, 9/18/08, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > From: Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > Subject: [Rails] Re: CUSTOM DATA TYPES > > To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > Date: Thursday, September 18, 2008, 5:45 AM > > On 18 Sep 2008, at 09:44, Jose G. wrote: > > > > Thanks Fred, > > > > If I have : > > > > class CreateModels < ActiveRecord::Migration > > > def self.up > > > create_table :models do |t| > > > t.Template1 :model, > > > t.Template2 :description, > > > t.Template3 :longdescription, > > > > t.timestamps > > > end > > > end > > > > I need to create the method inside > > "CreateModels" ? or Inside > > > "Models". > > > Neither. I was suggesting extending the TableDefinition > > (defined in > > schema_defintion.rb) > > > Fred > > > And then how can I use this "Template" in > > another "Table definition". > > > > Thanks. > > > > --- On Thu, 9/18/08, Frederick Cheung > > <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > wrote: > > > >> From: Frederick Cheung > > <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > >> Subject: [Rails] Re: CUSTOM DATA TYPES > > >> To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > >> Date: Thursday, September 18, 2008, 4:31 AM > > >> On 18 Sep 2008, at 09:26, Jose G. wrote: > > >>> How can I create something like a > > "template" > > >> or "pattern" that > > >>> includes for example ":default => > > "short > > >> Description", :limit => > > >>> 20", then I only use this template to > > create the > > >> new table. > > >>> Something like this : > > > >>> . > > >>> . > > >>> t.Template2 :description, # > > ''Template2'' > > >> includes ":default => "short > > >>> Description", :limit => 20" > > >>> t.Template3 :longdescription, # > > ''Template3'' > > >> includes ":default => > > >>> "long Description", :limit => > > 40" > > >>> . > > >>> . > > > >>> Then I will use this new type to create new > > fields > > >> with the same > > >>> characteristics in all the tables. > > > >> Well you could certainly add methods to the > > TableDefinition > > >> class > > >> (which is the class of the objects yielded by the > > >> create_table block) > > >> if you wanted to. > > > >> Fred > > >>> Thanks, > > > >>> Jose.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks Fred, I will try with two of them. About Plugins i found : http://nubyonrails.com/articles/2006/05/04/the-complete-guide-to-rails-plugins-part-i http://nubyonrails.com/articles/2006/05/09/the-complete-guide-to-rails-plugins-part-ii But, about libraries inside rails ..., do you know some places that i could read ? Thanks Jose. --- On Thu, 9/18/08, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> From: Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > Subject: [Rails] Re: CUSTOM DATA TYPES > To: "Ruby on Rails: Talk" <rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > Date: Thursday, September 18, 2008, 2:48 PM > On Sep 18, 7:29 pm, "Jose G." > <jgonzal...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote: > > Thanks agai Fred, > > > > If I change the file in rails directory : > > > > > Neither. I was suggesting extending the > TableDefinition > > > (defined in > > > schema_defintion.rb) > > I wouldn''t do that. This is ruby - you can reopen a > class whenever you > feel like it, eg stick it in a file in lib and require that > or (if > you''re going to reuse it across apps) make it into a > plugin. > > Fred > > > > Then If I upgrade to another rails version I need to > modify the file again ? > > > > Exists another way to put it inside the rails > application independent from rails upgrade ? > > > > Thanks, > > > > Jose. > > > > --- On Thu, 9/18/08, Frederick Cheung > <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > From: Frederick Cheung > <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > Subject: [Rails] Re: CUSTOM DATA TYPES > > > To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > > Date: Thursday, September 18, 2008, 5:45 AM > > > On 18 Sep 2008, at 09:44, Jose G. wrote: > > > > > > Thanks Fred, > > > > > > If I have : > > > > > > class CreateModels < > ActiveRecord::Migration > > > > def self.up > > > > create_table :models do |t| > > > > t.Template1 :model, > > > > t.Template2 :description, > > > > t.Template3 :longdescription, > > > > > > t.timestamps > > > > end > > > > end > > > > > > I need to create the method inside > > > "CreateModels" ? or Inside > > > > "Models". > > > > > Neither. I was suggesting extending the > TableDefinition > > > (defined in > > > schema_defintion.rb) > > > > > Fred > > > > And then how can I use this > "Template" in > > > another "Table definition". > > > > > > Thanks. > > > > > > --- On Thu, 9/18/08, Frederick Cheung > > > <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > > wrote: > > > > > >> From: Frederick Cheung > > > <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > >> Subject: [Rails] Re: CUSTOM DATA TYPES > > > >> To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > > >> Date: Thursday, September 18, 2008, 4:31 > AM > > > >> On 18 Sep 2008, at 09:26, Jose G. wrote: > > > >>> How can I create something like a > > > "template" > > > >> or "pattern" that > > > >>> includes for example ":default > => > > > "short > > > >> Description", :limit => > > > >>> 20", then I only use this > template to > > > create the > > > >> new table. > > > >>> Something like this : > > > > > >>> . > > > >>> . > > > >>> t.Template2 :description, # > > > ''Template2'' > > > >> includes ":default => > "short > > > >>> Description", :limit => > 20" > > > >>> t.Template3 :longdescription, # > > > ''Template3'' > > > >> includes ":default => > > > >>> "long Description", > :limit => > > > 40" > > > >>> . > > > >>> . > > > > > >>> Then I will use this new type to > create new > > > fields > > > >> with the same > > > >>> characteristics in all the tables. > > > > > >> Well you could certainly add methods to > the > > > TableDefinition > > > >> class > > > >> (which is the class of the objects > yielded by the > > > >> create_table block) > > > >> if you wanted to. > > > > > >> Fred > > > >>> Thanks, > > > > > >>> Jose. >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---