Hi all I need to know the number of a migration within the self.up() method, and I DON''T WANT TO RELY ON THE FILENAME (XXX_my_migration.rb). So is there a way to determine it somehow? def self.up puts ''doing migration number '' + migration_number() end Thanks a lot for help. Josh -- 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 -~----------~----~----~----~------~----~------~--~---
Jean-François Trân
2007-Apr-09 10:26 UTC
Re: Migrations: determine migration number in self.up()?
Hi Joshua,> I need to know the number of a migration within the > self.up() method, and I DON''T WANT TO RELY ON > THE FILENAME (XXX_my_migration.rb). > > So is there a way to determine it somehow? > > def self.up > puts ''doing migration number '' + migration_number() > endNot so nice, but you can try that : def self.up puts "doing migration number : #{::ActiveRecord::Migrator.current_version}" end -- Jean-François. -- Ruby ( http://www.rubyfrance.org ) on Rails ( http://www.railsfrance.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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Joshua Muheim
2007-Apr-09 10:41 UTC
Re: Migrations: determine migration number in self.up()?
Thanks a lot! May I ask what the prepended :: means and how it works? ::ActiveRecord::Migrator.current_version I remarked that the returned number does NOT correspond with the file name''s number. Is this because the file number itself is only used for sorting the migrations in ascending order and not because it is recognized as a number itself? Thanks. -- 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 -~----------~----~----~----~------~----~------~--~---
Joshua Muheim
2007-Apr-09 10:48 UTC
Re: Migrations: determine migration number in self.up()?
Another question: migration_number = ::ActiveRecord::Migrator.current_version.to_i gives me an error: String can''t be coerced into Fixnum What can I do? The output is "0" (zero), so why is there a problem? -- 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 -~----------~----~----~----~------~----~------~--~---
Joshua Muheim
2007-Apr-09 10:59 UTC
Re: Migrations: determine migration number in self.up()?
Joshua Muheim wrote:> Another question: > > migration_number = ::ActiveRecord::Migrator.current_version.to_i > > gives me an error: > > String can''t be coerced into Fixnum > > What can I do? The output is "0" (zero), so why is there a problem?Oh, I got this one myself. ;-) -- 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 -~----------~----~----~----~------~----~------~--~---