I setup a simple todo app using AngularJS to test out its functionality, and once I got the basics running I decided I wanted to add persistence to the data.
I decided to setup a local environment using MySQL and to give things a bit of a twist I decided to use Ruby instead of PHP for server access.
The problem comes from executing the Ruby script and retrieving the data. Right now, when I try to use $http in AngularJS all it does is return the ruby script, not execute it.
Here's relevant code for reference.
todo.js:
var module = angular.module('app', []);
module.service('MySQLConnect', function($http) {
this.getData = function() {
$http.get('api/todos.rb').success(function(data) {
console.log(data);
});
return response;
}
});
module.controller('TodoCtrl', function($scope, MySQLConnect) {
$scope.todos = MySQLConnect.getData();
});
todos.rb:
require 'mysql'
begin
connection = Mysql.new 'localhost', 'root', 'root', 'todo', 8889, '/Applications/MAMP/tmp/mysql/mysql.sock'
results = connection.query("SELECT * FROM todos")
todos = []
results.each_hash do |row|
todos.push(row)
end
todos
rescue Mysql::Error => e
puts e.errno
puts e.error
ensure
connection.close if connection
end
Right now, the console log for data is only returning everything written in todos.rb. How can I get it to actually execute the script and return the todos array?