Guest User

Untitled

a guest
May 27th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. around_filter :hijack_db
  2.  
  3. def hijack_db
  4. begin
  5. ActiveRecord::Base.connection = ActiveRecord::Base.establish_connection(
  6. :adapter => "mysql",
  7. :host => "localhost",
  8. :username => "root",
  9. :password => "",
  10. :database => @nejaka_ta_db
  11. )
  12.  
  13. yield
  14. rescue Mysql::Error
  15. # DB NEEXISTUJE NEBO JE NEJAKY PROBLEM
  16. ensure
  17. # nakonec to vracime zpet
  18. ActiveRecord::Base.establish_connection( RAILS_ENV.to_sym )
  19. end
  20. end
Add Comment
Please, Sign In to add comment