Tuesday, November 17, 2009

employees-directory a new Radiant CMS extension

Martian Interactive has created a new Radiant CMS extension to support large number of employees information. A more detailed information about the extension can be found in the company's blog or the project repository.

Thursday, November 05, 2009

Simple Rake task for dumps on SQLite

In previous posts I showed you some Rake tasks that I constantly use to make dumps and dump import operations on a database, these scripts were designed to work with MySQL.


Even when SQLite has become the default Rails DB (since Rails 2.0.2), I preffer to work with MySQL, but in the last days I had to make some work using SQLite, and since dump tasks save you a lot of time, here's the simple script I wrote to make this work with SQLite. I hope you find this useful.


Tuesday, September 15, 2009

Migrating ezgraphixdemo from HerokuGarden to Heroku

HerokuGarden is not longer supported, so I had to migrate the ezgraphix demo to Heroku, that process was really simple and elegant, the guys behind Heroku have done a great work, I still remember the first days of Heroku (when we needed a beta account), deployment and performance weren't as good as they are today, there is a big enhancement since these days and this will help people to easily deploy Rails apps, so keep up the good work!


So here's where you can find the new demo http://ezgraphixdemo.heroku.com/

Sunday, August 30, 2009

Simple Rake task for dumps

Rails ships with a lot of rake tasks, you can check the defaults by typing rake -T from your project's root, many of them make operations over the database, like; create, drop, reset, clone among others, but we wanted a simple rake task to generate dumps and import them into the current environment's db, Rails include a dump task that generates your current db schema, in our case we dump everything, data and schema in a sql file. You can find a LOT of rake tasks for dumps out there, but I like this simplicity!



Tuesday, May 05, 2009

Overriding RAILS_ASSET_ID based on the last git commit number

Lately I've been working with some 3D contents made in Unity3D and having Rails as web support in order to visualize those contents. I had to override the ENV["RAILS_ASSET_ID"] variable value in order to make the contents cacheables between commits changes, I'm using Git as scm, so I wanted to use the last commit number as value for the asset id, (there is another similar post for svn), this is exactly what I did:





The first line gets the last commit number and stores it in the variable, then it can be used to make objects cacheables.

Stylesheets, javascripts, etc ... also will get this asset id as default.

Tuesday, February 17, 2009

Deploying Sinatra applications with Capi, nginx and Thin.

I've been working with Sinatra for less than a month and there are some things I have to say about it;


Sinatra is an awesome framework to build tiny web applications that helps you a lot to understand how a framework works, but the documentation it's almost reduced to the Sinatra Book and some blog's posts, I didn't find a full guide in how to deploy a Sinatra app + Capi + Thin + nginx, just clues from different sites that I had to link in order to make it work, and I'm gonna show you how I did it.

I assume you have everything installed, sinatra, rack, thin, nginx and capistrano, also I'm using Git as scm and github as hosting.

Another consideration, my user and application name is: 'acoplet', change it according to your situation, this is the application structure:


project_root
==Capfile
==config.ru
==public
==javascripts
==stylesheets
==thin
==production_config.yml
==tmp
==pids
==thin.pid
==views
==log

Step 1, create and configure the thin config file, usually for production purposes, this is how your production_config.yml file should looks like,


Change the chdir value with the location of your application, also for pid, rackup, and log according to the application structure, please note the /current/ it's capistrano!

Step 2, Create manually the Capfile, you can't use capify here since this is not a Rails app!


Again, change the repository, application, user, deploy_to and host variables according to your project, in my case I'm using a github repository, usually I put my application under ~/www/#{application}/  where each application has a related user with the same name (make things easy for me), in this case /acoplet/www/acoplet/ and then let capistrano make it's stuff.

Step 3, Create the config.ru file


At the moment of writting this post, this is the right way to edit the config.ru file, things like:


Are deprecated now, you have to replace the require 'acoplet', with your main file, the file when you put all the sexy code.

At this moment, you should be able to upload (if you want) your repository and start the deployment process, when done setting up the repository, let's start with the capistrano tasks!, run:

cap deploy:setup
cap deploy:check
cap deploy:cold


If everything went fine, the backend server for the sinatra application should be up and running in the remote host (in the port 8000 for the example) to check it, ssh the remote host and run:

curl -v localhost:8000


step 4, Nginx front server configuration, you have to create vhost for the application, do it unter the the sites-available directory in your nginx main nginx folder (probably /etc/ngninx/ depending in how you installed nginx). and then enable it through a symbolic link under the sites-available folder

The Nginx vhost file should looks like:


I don't have any domain registered for this, but if you have, you should setup your dns configuration and just change the server_name variable with your domain name, again change the location according to your needs, restarting nginx should be enough to let you see the nice Sinatra App up and running!

Hope this little guide help you with the deployment process with Sinatra!

Wednesday, February 11, 2009

Queries with created_at and time zones.

Time zones support in Rails is a great feature that simplifies and makes easy a task that would take too much time in other frameworks, but there are some situations in which we should take care about queries regarding utc convertions, for example, for my last rails app, I'm working with 'Americas/Bogota' (UTC -5) as default time zone to parse the time from the server time to Colombian zone and then print information about the records (created_at or updated_at) Rails makes this pretty well,  but you should notify that in the database the time fields are created and saved with the current SERVER time, so in order to make queries relating the current time zone and the server time, you have to parse again the current time zone to the server time using the TZinfo local_to_utc method, otherwise, the queries eventually will not return the expected results.

Full example:

Older Posts

Blogger Template Inspired by Blogcrowds