Monday, December 17, 2012

Bootstrap + ActiveAdmin + Devise in Heroku in seconds


1. git clone git@github.com:fzuppa/bootstrap-devise-activeadmin-in-heroku.git
2. git remote rm origin
3. rm -Rf .git
4. rm -Rf .gitignore
(Instead of the previous 4 steps, you could also download the application in Github)
5. git init
6. rails g scaffold Interview name:string
7. rake db:migrate
8. rake db:seed
9. rails g bootstrap:themed Interviews (Y for everything)




There you go, you got your application running in a few seconds.
You should change the name of the app for yours
You could also change the default locale, as spanish translations are included (in application.rb)

The url for active admin is localhost:3000/admin with admin@example.com/password

Gems included
https://github.com/seyhunak/twitter-bootstrap-rails
https://github.com/ryanb/nested_form
https://github.com/amatsuda/kaminari
http://activeadmin.info/documentation.html

A better way to do this is to use Rails Composer, but I had the openssl problem





Thursday, July 12, 2012

blank?, present? or what?...

How do you test if a boolean field is false? I mean, if it has the value false, because nil has a boolean value of false in Ruby, right?

Let's see the Object API a bit


blank?()
An object is blank if it’s false, empty, or a whitespace string. For example, “”, “ ”, nil, [], and {} are all blank.

and


present?()
An object is present if it’s not blank?.


So probably you should be thinking that present? should be the method to use

myInstance.field.present? && myInstance.field?

But this is not correct, as myInstance.field.present? is false. myInstance.field.blank? is true, and so !true is false

So the solution is

!myInstance.field.nil? && myInstance.field?

Thing with this solution is we have a system of 3 values, because nil would be different than false.

Does this make sense?




Saturday, February 25, 2012

Automated Backups + Store them in S3 in Heroku

A few days back, I needed to write a rake task to backup my database daily and store it in S3. Googling a little bit, I found out there posts like this one, that teach you how to do it and even a gem that simplifies your work. I also found out that Heroku has an addon called PGBackups to do exactly that, holding until 7 daily backups. So the only thing I needed to do was transfering the generated backup to S3 (we want to retain up until a year of backups). Slicing the transfering chunk of code from one of the available posts, I created this rake task


That transfers the latest backup to S3. The interesting part of this code is this line

 public_url = "heroku pgbackups:url --app <heroku_app_name>"

That publishes temporarily the url of the latest backup to be transfered.

Isn't it cool Heroku? I love it.