Hi, guys. I changed some columns types to decimal in database, but the code is not DIY. Any thoughts on refactoring the following code? change_table :accounts do |t| t.change :check_amount, :decimal, :precision=>6, :scale=>2, :default=>0 t.change :cash_amount, :decimal, :precision=>6, :scale=>2, :default=>0 t.change :change_amount, :decimal, :precision=>6, :scale=>2, :default=>0 . . . . t.change :total, :decimal, :precision=>6, :scale=>2, :default=>0 end Thanks in advance. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Apr 21, 2010, at 10:32 AM, Ichiro Saga wrote:> Hi, guys. I changed some columns types to decimal in database, but > the > code is not DIY. Any thoughts on refactoring the following code? > > change_table :accounts do |t| > t > .change :check_amount, :decimal, :precision=>6, :scale=>2, :default=>0 > t.change :cash_amount, :decimal, :precision=>6, :scale=>2, :default=>0 > t > .change > :change_amount, :decimal, :precision=>6, :scale=>2, :default=>0 > . > . > . > . > t.change :total, :decimal, :precision=>6, :scale=>2, :default=>0 > endchange_table :accounts do |t| [:check_amount, :cache_amount, :change_amount, ..., :total].each do |c| t.change :c, :decimal, :precision => 6, :scale => 2, :default => 0 end end -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Apr 21, 2010, at 10:56 AM, Philip Hallstrom wrote:> > On Apr 21, 2010, at 10:32 AM, Ichiro Saga wrote: > >> Hi, guys. I changed some columns types to decimal in database, but >> the >> code is not DIY. Any thoughts on refactoring the following code? >> >> change_table :accounts do |t| >> t >> .change >> :check_amount, :decimal, :precision=>6, :scale=>2, :default=>0 >> t >> .change :cash_amount, :decimal, :precision=>6, :scale=>2, :default=>0 >> t >> .change >> :change_amount, :decimal, :precision=>6, :scale=>2, :default=>0 >> . >> . >> . >> . >> t.change :total, :decimal, :precision=>6, :scale=>2, :default=>0 >> end > > change_table :accounts do |t| > [:check_amount, :cache_amount, :change_amount, ..., :total].each do > |c| > t.change :c, :decimal, :precision => 6, :scale => 2, :default => 0Oops... that should be: t.change c, ..... (no colon before the c)> end > end > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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 > . >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Philip Hallstrom wrote:> On Apr 21, 2010, at 10:56 AM, Philip Hallstrom wrote: > >>> :check_amount, :decimal, :precision=>6, :scale=>2, :default=>0 >>> end >> >> change_table :accounts do |t| >> [:check_amount, :cache_amount, :change_amount, ..., :total].each do >> |c| >> t.change :c, :decimal, :precision => 6, :scale => 2, :default => 0 > > Oops... that should be: > > t.change c, ..... > > (no colon before the c)Thank you for your help. It''s much cleaner now. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.