Category Archives: Coding

coding stuff

Alternative way to get username from facebook API*

My site ( using facebook graph for user login. I haven’t maintenance it for the last 2 months. when I try to login few days ago it return an error because the username  from Facebook graph API was empty.

I googled why this is happened. and got that facebook has depecrated the /me/username API. alternatively we can use email as username. but I resist to use facebook username as my application users username. so I do some trick.. seems stupid but it works.

Continue reading

Membuat "Application Automator" dengan applescript [Mac OS]

Mungkin kita sering mengalamin betapa ribet nya menjalanakan sebuat aplikasi RoR dikarenakan membutuhkan beberapa services.. contoh.. untuk menjalanan sebuah aplikasi RoR kita harus menjalankan server Mongo, RedisFakeS3, Web Server (Consumer) & Web Server (API).

salah satu solusinya adalah menggunakan “Automator” (Applescript), sebenernya masih bisa di handle pake foreman, tapi entah kenapa di local komputer lokal gue kadang-kadang suka suka ke “halt” session nya… jadi deh kepaksa bikin script automator… berikut langkah2nya:

1. cari di spotlight aplikasi namanya “Automator”

2. pilih “Application”

3. pilih “Utilitites” > “Run Applescript”

4. berikut script Automator nya

5. Save as application and run 🙂


How to update all in mongoid

in Active record we simply use Model.update_all() then how we do that in mongoid ?
simple.. use collection.update, example:

Save Facebook user data into the database after Authentication using Oauth2

This post is a reply from someone who emailed me, he asked me how to save the user data that already login to our site using facebook graph API.
after we create a login scheme using facebook and oauth2 gem, we need to save the facebook user data to our databases, so.. how to save it into the database?

it’s very easy and simple, when we get a callback from the facebook graph API and save the user data in session like this:

session[:fb_user] = JSON.parse access_token.get(‘/me’)
session[:user] = User.save_user_data(session[:fb_user])

Continue reading

how to make layout false for devise controller

since I wanna use the login page as a popup box use facebox.. not to redirected the user. the whole layout is appear to the facebox.. so how to make the layout false if we use devise?

simple.. check the current controller is a Devise::SessionsController or not in ApplicationController :

How to solve `cached_specs': undefined method `spec' for nil:NilClass error

I try to run “bundle install” (bundler gem) and in the middle of the installation process i got my hardisk space is full. so i cut the process and remove some data then try to install again, so i run the “bundle install” again and get error like this :

/usr/lib/ruby/gems/1.8/gems/bundler-1.0.0/lib/bundler/source.rb:199:in `cached_specs': undefined method `spec' for nil:NilClass (NoMethodError)

from/usr/lib/ruby/gems/1.8/gems/bundler-1.0.0/lib/bundler/source.rb:196:in each'

from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0/lib/bundler/source.rb:196:in cached_specs’

and many moooorreeee…..

that error caused of Continue reading

Create Recurring job using delayed job

basically delayed job is using for background job. but we can use it as a recurring job.
here’s the step

first, install delayed_ojb gem. you can see how to install it at

then add a new library to your rails apps directory ( /Libs ) e.g: jobs.rb Continue reading

facebook authentication using oauth2 gem in rails

in this section,  i wanna share how to intregrate the Facebook’s new OAuth authorization in Ruby On Rails, using oauth2 gem.

let’s get started !

first, install the oauth2 gem, you can get it from here

then create a controller call oauth_controller.rb Continue reading