John Merlino
2011-Jul-11 16:51 UTC
when iterating tables with ActiveRecord::Base.connection, how do you check if a string is equal to the current table iteration?
Hey all,
This here is not working:
task(:load_selected => :load_config) do
IgnoreTables = %w(''students'')
begin
ActiveRecord::Base.establish_connection
ActiveRecord::Base.connection.tables.each do |table|
if IgnoreTables.include? table
puts "Its true"
next
else
ActiveRecord::Base.connection.execute("TRUNCATE #{table}")
end
end
end
end
Despite that some point table will be equal to students and students
is in the IgnoreTables array, it should skip to the next iteration,
but rather the else is triggered and the table is truncated.
Anyway know how to address this? Is there a method part of connection
that will help me achieve what I am trying to do?
Thanks for response
--
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.
Frederick Cheung
2011-Jul-11 19:01 UTC
Re: when iterating tables with ActiveRecord::Base.connection, how do you check if a string is equal to the current table iteration?
On 11 Jul 2011, at 17:51, John Merlino <stoicism1-YDxpq3io04c@public.gmane.org> wrote:> Hey all, > > This here is not working: > > task(:load_selected => :load_config) do > IgnoreTables = %w(''students'')I think you''ll find that this array is ["''students''"] but you expected it to be ["students"] Fred> begin > ActiveRecord::Base.establish_connection > ActiveRecord::Base.connection.tables.each do |table| > if IgnoreTables.include? table > puts "Its true" > next > else > ActiveRecord::Base.connection.execute("TRUNCATE #{table}") > end > > end > end > end > > Despite that some point table will be equal to students and students > is in the IgnoreTables array, it should skip to the next iteration, > but rather the else is triggered and the table is truncated. > > Anyway know how to address this? Is there a method part of connection > that will help me achieve what I am trying to do? > > Thanks for response > > -- > 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. >-- 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.