0

I am a newbie to Ruby and have expirienced a problem with a PostgreSQL Database on Heroku.

So, I have written a little app which stores time entries: http://timekeper.herokuapp.com/

Now i have deployed the application to heroku and connected it with a Postgre Database.

Expected Behaviour

After pressing the "Speichern"-Button an AJAX Request is fired an should update the table and the right diagram.

Problem

The AJAX Request is being responsed but seems to be empty there is not data in it.

What have i tried?

The logs (´heroku logs´) doesnt contain anything suspicious.

I have tracked down the problem to one Command:

data = DateTime.now
time_a = DateTime.new(data.year, data.month, data.day)
time_b = DateTime.new(data.year, data.month, data.day, 23, 59, 59, 59)
Entry.all(:starttime => time_a..time_b, :order => [starttime.desc]) #=> []

The database contains Entries because ´Entry.all´ returns the entries.

This is a picture of an irb Session on Heroku with the loaded app.rb: irb Session on Heroku

When i connect the PostgreSQL Database on Heroku with my local System. Everything is working!

If you want to examine the whole source code, you can find it on GitHub: https://github.com/Reflic/timekeeper

Thank you for your Help, Kevin

Edit 1 This is the AJAX Javascript Code:

function hour_chart(loading){
  if(loading){
$('#hour').html('');
  }
  $.ajax({
url: '/api/percenttoday',
type: 'GET',
data: '',
success: function(obj) {
    Morris.Donut({
        element: 'hour',
        data: [
            {label: "24h", value: obj.workpercent},
            {label: "24h", value: obj.offpercent}
        ],
        colors: ['#679DC6', '#6D6D6D'],
        formatter: function (y){return y+' %'}
    });
}
});
}

This is the ruby router:

get '/api/percenttoday' do
today_data = Stats.prepare(Stats.today(DateTime.now));

workpercent = (today_data[1].last * 100) / Dtutil::DAYSECONDS
offpercent = 100 - workpercent
json :workpercent => workpercent, :offpercent => offpercent
end

And here is the Stats Module: https://github.com/Reflic/timekeeper/blob/master/utilities.rb

4

0 回答 0