I'm creating a website using 3 principle files.
For the moment I have these 3 files working but separately. Now I'm trying with MAMP (I'm on MAC) to make this 3 files work together. First I'm trying so save data in my MAMP database using my ruby code. I red that active record was the best way to do it, but the following code isn't working, can you help?
ActiveRecord::Base.establish_connection(
:adapter => "mysql2",
:host => "localhost",
:username => "root",
:password => "root",
:database => "my_database"
)
Base.connection.insert("INSERT INTO my_database(fields) VALUES('value')")
Try this:
connection = ActiveRecord::Base.establish_connection(
:adapter => "mysql2",
:host => "localhost",
:username => "root",
:password => "root",
:database => "my_database"
).connection
connection.exec_query("INSERT INTO my_database(fields) VALUES('value')")