Tags

If you run the rails console, by default it is using the DEVELOPMENT database connection setting. In case you want to switch to TEST database, you just simply update the current connection to “test”. See below the script:

c:\>railsapp\myapp\>rails c
irb(main):010>ActiveRecord::Base.establish_connection "test"
irb(main):011>connection = ActiveRecord::Base.connection()
irb(main):012>connection.execute("Your sql goes here to execute in test database")
irb(main):013>ActiveRecord::Base.establish_connection "production" #switch to production or development
Advertisements