Time since timestamp - ruby-on-rails-3

Im trying to figure out the best way to find the amount of time since the created_at timestamp was placed on an article in my database. Id like it to be in minutes, then hours, then days.
I dont know where to really get started here. Any suggestions?

There's the distance_of_time_in_words helper for Rails which is kind of "vague" when it comes to times, so a friend and I re-wrote it into a gem called dotiw which would provide what you're after.

Related

Postgres Trigger in specified time

Hello expert I am working in banking software vendor company and we are working in PostgreSQL database due to load of work in office time(pick hour) I want to execute some function in specified time(off hour) with trigger. So please if you have any idea please help me.
A trigger should always be something fast. You don't want to hold transactions open for a couple of hours, that would be a really bad idea.
The correct solution for such a problem would be a queue. There are some existing implementations like PGQ, but I don't know if the'll meet your requirements.

Automated Heroku PostgreSQL Updates without Client Request

I am new to web development. I am building a simple text based web game. I am using heroku and postgresql. I have sql table for users and their coin amount(their earnings).
I can receive/transmit data from this database by using requests made from players. However what I want to achieve is to automate the coin addition to each users account.
So let's say at the beginning of each hour, I want to add 15 coins to each user. How can I possible achieve this kind of automation with heroku and postgresql ?
I tried searching for almost an hour, but I wasn't even able to find the name of this process :(
While you could schedule this (as sonnyhe notes), it's probably better not to.
Instead, just update the value when you're updating their balance for some other reason, by adding the difference between the time you last added coins and the current time, extracting the hours, and multiplying by 15.
If the user asks to just view the balance, all you need to do is display its last stored value plus the hours since then * 15.
That way you're not doing lots of unnecessary updates and causing unnecessary load.
Here is a gem you can look into.
Just include the gem rufus-scheduler in your gemfile.
The you can set something up in you config/initializer/scheduler.rb
scheduler.every '15m' do
# Update all coins with 15 more.
end

Webmatrix - Regularly run a SQL query

i have an SQL query (shown below) that i need to run on a regular basis:
db.execute("UPDATE property_info SET IsActive=false WHERE ExpiryDate > #0", CurrentDate);
This query is basically intended to check ALL properties, and to see whether or not they are past their expiration date. If they are, then it will automatically set the property to Inactive. Because "CurrentDate" is a rolling window, i want to re-run this query automatically, probably every day.
Is this something i should be using a stored procedure for?
Any suggestions on the best way to achieve this without any user interaction?
One simple way to achieve this would be to add the line of code to _PageStart.cshtml in the root of your project. This will make it execute every time any page on the site is executed. That is probably massively overkill for something that, by the looks of it, only needs to be checked once a day or so. To alleviate this you could employ a simple DateTime stamp in the Application collection to make sure it only runs a maximum of once every day or so (or tune the interval as appropriate for your needs). This is in no way a solution for fully scheduled code execution, but it may well serve your purposes (and your budget).

Heroku dataclips result is different from local DB result

I ran a SQL query using the dataclips feature on Heroku. It works great - the results I get are in the correct order, because part of my clause specifies "ORDER BY ...".
I just pulled a copy of my database from Heroku. I then run ActiveRecord::Base.connection.execute ""
The data I get is correct, but the PGResult object has the data ordered in a completely random way -- i.e. my "order by" clause is totally ignored.
I am wondering why that is happening and if there is anyway to prevent that.
We are now using the same version of Postgres as Heroku and we get the same dataset. It is, however, not correctly ordered still. The order by clause is still not working properly so we are just forcing a sort using rails (since we limit the result by 10, its not a lot of work for Rails).
I'm posting this because no one seems to have a good answer and we haven't found anything that works either. Might as well let other folks know that for some reason, there seems to be an issue. Going to dig around a bit and potentially report a bug to postgresql folks.

Migration number not taking timestamp

Recently we moved our application from rails 2.3.11 to rails 3.0.7, after everything was done we saw a weird issue. Whenever we generate a migration, the number is auto incrementing where as we needed migration number in UTC timestamp. Since there are 5 members in our team, its causing very big problem.
Kindly help me to resolve this issue.
Set config.active_record.timestamped_migrations = true in your config/application.rb