How to check if Rails 3.2 can connect to MySQL?

Is there an easy way for the command line / console to check if the Rails application is correctly connected to MySQL?

Unfortunately, I cannot start the Rails console. He complains:

/home/nexargi/www/gi/vendor/ruby/1.9.1/gems/activerecord-3.2.1/lib /active_record/dynamic_matchers.rb:50:in `method_missing': undefined local variable or method `abddadhocbkgid' for #<Class:0x000000036427f8> (NameError) from /home/nexargi/www/gi/app/models/adhoc_bkg_diners_diet.rb:5:in `<class:AdhocBkgDinersDiet>'. 

"abddadhocbkid" is the first attribute of the first table, so I think it does not control the connection to the mysql database. I need to find a way to check if Rails can connect to the mysql database without logging into the rails console.

Here is my model code:

 class AdhocBkgDinersDiet < ActiveRecord::Base validates_presence_of :abddadhocbkgid, :abddmealdietid, :abddadultnos, :abddchildnos validates_numericality_of :abddadultnos, :abddchildnos, greater_than_or_equal_to: 0 belongs_to :adhoc_bkg, foreign_key:abddadhocbkgid belongs_to :meal_diet, foreign_key: :abddmealdietid end 
+4
source share
2 answers

If you just need to check if your connection is really active after it is created, is there an ActiveRecord::Base.connected? .

+13
source

You can connect directly to the console using the console:

 ActiveRecord::Base.establish_connection( Rails.configuration.database_configuration[Rails.env] ) 

Or, if you have a model, you can try to find it:

 SomeModel.first 
+6
source

Source: https://habr.com/ru/post/1398277/


All Articles