Archive for the ‘Ruby on Rails’ Category

5 Popular Websites Built by Ruby on Rails

Cara Menggunakan Appschef API dengan w_platform Gem.

Tutorial adalah SAAS dari Indonesia yang dibuat menggunakan Ruby on Rails. Berikut ini langkah – langkah untuk menggunakan Appschef API dari Aplikasi Ruby on Rails 3.2 dengan gem w_platform:

  • Signup dan Daftarkan produk / aplikasi Anda di
  • Login ke dan dapatkan API_KEY untuk produk / aplikasi yang anda daftarkan
  • Edit Gemfile aplikasi Rails anda dan tambahkan code berikut:
gem 'w_platform', :git => ''
  • Di terminal run:
$ bundle install
$ rails generate w_initializer install
  • Kemudian Edit file config/w_platform.yml sesuai dengan konfigurasi aplikasi Anda, berikut contohnya:
common: &default_settings
w_api_url_users: /api/users/
w_api_url_get_active_session: /api/login
#nama aplikasi / produk Anda
app_name: w_factory_operations
<< *default_settings
# link ke website appschef
# ganti dengan Api key produk / aplikasi Anda
api_key: xxxxxxxxxxxxxxxxxxxxxxxx
# link ke website Anda
app_url: http://localhost:3000
# protokol yang digunakan ( pilihan bisa http atau https )
protocol: https
#nama controller dan action yang dijadikan root (“/”) di Aplikasi Anda
root_controller: home
root_action: index
  • Definisikan “key” untuk setiap fitur yang ada di aplikasi Anda.

Untuk menentukan fitur apa saja yang ada di Aplikasi Anda, Appschef mengharuskan anda untuk membuat daftar fitur dan “key” sebagai representatifnya. List itu harus anda buat dalam excell dan upload ke

Kemdian setelah itu anda definisikan fitur tersebut di aplikasi anda dengan edit file config/w_features.yml, berikut contohnya:

index: wfo_home_index
new: wfo_project_new
show: wfo_project_show


home, Projects => Nama Controller

index, new, show => Nama Action

wfo_home_index  => Contoh  ‘key’ untuk fitur “home/index”

  • Mount Routes WPlatform dengan edit config/routes.rb dan tambahkan code berikut:
mount WPlatform::Engine => “/”, :as => “w_platform”
  • Include WPlatformHelper dan tambahkan before filter untuk check access user ke fitur yang ada di Aplikasi Anda. Sebagai contoh Anda dapat Edit application_controller.rb dan tambahkan 2 line berikut:
include WPlatformHelper
before_filter :check_user_access
  • Langkah terakhir, Run server aplikasi Anda, kemdian login dari server appschef dan pilih untuk membuka Aplikasi Anda.


  • Anda dapat mendefinisikan controllers dan actions yang tidak memerlukan check authentikasi dengan cara berikut ini:
before_filter :check_user_access_but_skip_some_actions
def check_user_access_but_skip_some_actions
check_user_access([{:controller_name => “about”, :action_name => “index”}])
  • Anda dapat menggunakan helper yang tersedia, yaitu:

current_user_platform =>return has semua result data yang diberikan oleh Appschef server

current_company => return hash data company

current_products => return has data products

current_features => return hash fitur – fitur yang boleh diakases user

  • Menambahkan link logout
<%= link_to “Logout”, w_platform.new_authentication_session_cleaner_path, :confirm => “Anda yakin untuk logout ? ?”%>

Bug Report

Jika Anda menemukan bug dalam tutorial ini atau gem w_platform, harap hubungi saya melalui email ke:

Terima kasih.

ROR Application for solved Mars Rover Problem

Download the app here:


A squad of robotic rovers are to be landed by NASA on a plateau on Mars. This plateau, which is curiously rectangular, must be navigated by the rovers so that their on-board cameras can get a complete view of the surrounding terrain to send back to Earth.

A rover’s position and location is represented by a combination of x and y co-ordinates and a letter representing one of the four cardinal compass points. The plateau is divided up into a grid to simplify navigation. An example position might be 0, 0, N, which means the rover is in the bottom left corner and facing North.

In order to control a rover, NASA sends a simple string of letters. The possible letters are ‘L’, ‘R’ and ‘M’. ‘L’ and ‘R’ makes the rover spin 90 degrees left or right respectively, without moving from its current spot. ‘M’ means move forward one grid point, and maintain the same heading.

Assume that the square directly North from (x, y) is (x, y+1).

The first line of input is the upper-right coordinates of the plateau, the lower-left coordinates are assumed to be 0,0.

The rest of the input is information pertaining to the rovers that have been deployed. Each rover has two lines of input. The first line gives the rover’s position, and the second line is a series of instructions telling the rover how to explore the plateau.

The position is made up of two integers and a letter separated by spaces, corresponding to the x and y co-ordinates and the rover’s orientation.

Each rover will be finished sequentially, which means that the second rover won’t start to move until the first one has finished moving.

The output for each rover should be its final co-ordinates and heading.


Test Input:
5 5
1 2 N
3 3 E

Expected Output:
1 3 N
5 1 E

Error Twitter Api search – Sorry, your query is too complex. Please reduce complexity and try again.


I am found interesting case in twitter api search using geocode params.
When I call:
it’s returned
Sorry, your query is too complex. Please reduce complexity and try again.

Strange,.because This call working some days ago.
And I spend some minutes and found that we can’t request more than 160km
This the right call:

Sample of rails application – basic user system ( signup, login, edit profile etc )


I want to share rails 2 app sample.
It includes
– signup
– login
– activation ( via email )
– forgot password ( send to email )
– edit profile
– create member area
– simple layout for front end and member ( include basic css )
– script to feeds table countries

To run application, Please Follow this steps:

Checkout app

git clone

Change configuration

– change configuration for database myql in config/database.yml with yours

– change google account for sending email in config/application.yml
smtp_user_name: yourgmailaccount
smtp_password: yourgmailpassword

– rake db:create && rake db:migrate
– rake migration:populate
– ruby script/server

Hope this help people !

How to use linkedin api – invite people by email in ruby on rails

Hi guys,

This is quick tutorial about linkedin api 1 – invitation by people email to join your linkedin network.

We will use linkedinapi rails plugin ( Created by Dimas Priyanto and Me base on oauth rails plugin )

  • initialize your linkedin api key and secret key
>> linkedin_api_key = ” YOUR LINKEDIN API KEY”

>> secret_key = “YOUR LINKEDIN API SECRET”

  • setting your callback
  • create oauth object
>> oauth =, linkedin_secret)
  • request authorize url

Open the link in your browser  as redirection url for user to do authorization process,
if user authorize it we will get params[:oauth_verifier] in our “callback_url”,
use it to authorize from request

for example:

  • authorize using oauth verifier and token
>> oauth.authorize_from_request(oauth.request_token.token, oauth.request_token.secret, oauth_verifier)
  • create linkedin api object
>> linkedin =
  • show your linkedin profile
>> linkedin.profile
“<?xml version=\”1.0\” encoding=\”UTF-8\” standalone=\”yes\”?>\n<person>\n  <first-name>Feby</first-name>\n  <last-name>Artandi</last-name>\n  <headline>Ruby on rails programmer</headline>\n  <site-standard-profile-request>\n    <url>;key=30011332&amp;authToken=nM0a&amp;authType=name&amp;trk=api*a101208*</url&gt;\n  </site-standard-profile-request>\n</person>\n”
=> “<?xml version=\”1.0\” encoding=\”UTF-8\” standalone=\”yes\”?>\n<person>\n  <first-name>Feby</first-name>\n  <last-name>Artandi</last-name>\n  <headline>Ruby on rails programmer</headline>\n  <site-standard-profile-request>\n    <url>;key=30011332&amp;authToken=nM0a&amp;authType=name&amp;trk=api*a101208*</url&gt;\n  </site-standard-profile-request>\n</person>\n”
  • invite people by email, first name and last name
linkedin.invite_by_email(“”, “Feby”, “Artandi”)

That’s it, enjoy ! 🙂

Simple code to test twitter oauth with ruby on rails via web browser

Hi,This is tutorial about implement twitter oauth in Ruby on Rails application using twitter_oauth gem.

You can see installation from The gem author show how to implement the oauth call in command prompt.

Now I’ll show you how to use the gem via web browser and save access key into database.

1. Create rails application ( if it’s your 1st rails project you should google about ruby on rails app )

2. Implement the restful authentication plugin ( see ) until you have user system.

3. Install the twitter_oauth gem

4. Create migration

class CreateTwitterAccounts < ActiveRecord::Migration

  def self.up
    create_table :twitter_accounts do |t|
      t.integer :user_id
      t.string :token
      t.string :secret

  def self.down
    drop_table :twitter_accounts

5. Edit user model, add this line

  has_one  :twitter_account, :dependent => :destroy

  def has_twitter_oauth?
    self.twitter_account and self.twitter_account.token and self.twitter_account.secret

  def create_or_update_twitter_account_with_oauth_token(token, secret)
    twitter_account = self.twitter_account ? self.twitter_account : =>
    twitter_account.token = token
    twitter_account.secret = secret!

6. Create and edit Model twitter_account ( ruby script/generate model twitter_account )
   Add this line: 

   belongs_to :user

7. Create try controller ( ruby script/generate controller try )
8 Edit try controller and copy-paste this:

   # require the gem twitter_oauth
   require 'twitter_oauth'
   # need user logged in
   before_filter :login_required

   #initialize your twitter key and secret ( you can get from here )
   TWITTER_KEY = '83evR5lsb0E1gmvn0FXacQ'

   # The url to back when user has authorize your app
   TWITTER_CALLBACK_URL = 'http://localhost:3000/try/callback'

    #index method
    # this method check if user has authorize your app
    # if no it'll show they link to authorize your app in their twitter account
    def index
      if !current_user.has_twitter_oauth?
        @T_OAUTH = :consumer_key => TWITTER_KEY, :consumer_secret => TWIITER_SECRET )
        @T_REQUEST_TOKEN = @T_OAUTH.request_token :oauth_callback => TWITTER_CALLBACK_URL
        @T_TOKEN = @T_REQUEST_TOKEN.token
        @T_SECRET = @T_REQUEST_TOKEN.secret
        @link = @T_REQUEST_TOKEN.authorize_url
        session['token' ] = @T_TOKEN
        session['secret'] = @T_SECRET

  # Method callback
  # this method will call after user authorize your app in twitter website
  # this method will authorize oauth token and verifier send from twitter and if success key and secret will stored in database
  def callback
    @T_OAUTH = => TWITTER_KEY, :consumer_secret => TWIITER_SECRET )
    @oauth_verifier = params[:oauth_verifier]
    access_token = @T_OAUTH.authorize(session['token'], session['secret'], :oauth_verifier => @oauth_verifier)
    if (@result = @T_OAUTH.authorized?)
      current_user.create_or_update_twitter_account_with_oauth_token(access_token.token, access_token.secret)
      session['token'] = nil
      session['secret'] = nil
      flash[:notice] = "Authorize complete"
      flash[:notice] = "Authorize failed"

      flash[:notice] = "Authorize failed"

  # method update status
  # this method is for sent tweet to your twitter
  def update_status
    if current_user.has_twitter_oauth?
      @T_OAUTH = :consumer_key => TWITTER_KEY,
      :consumer_secret => TWIITER_SECRET, :token => current_user.twitter_account.token,
      :secret => current_user.twitter_account.secret )

      if @T_OAUTH.authorized? and @T_OAUTH.update(params[:status])
        flash[:notice] = "Your tweet has been sent"
        flash[:notice] = "Sorry ! Your tweet failed to sent, try later !"
      flash[:notice] = "You dont have twitter account with oauth token, please authorize myapp in your twitter !"

   redirect_to :action => 'index' 

9. Add file index.html.erb in app/views/try
    Copy - paste

    Test Twitter API

     <% if @link %>
        You have not authorize my app into your twitter 

       <%= link_to "Click here to authorize", @link %>
     <% else %>
        Try to update your status 

        <% form_tag "/try/update_status", :method => "post" do %>
          <%= text_field_tag "status" %>
          <%= submit_tag "Update" %>
        <% end %>
      <% end %>

10. Add file callback.html.erb in app/views/try
   copy - paste

   <%= flash[:notice] %>

   <%= link_to "Click here", "/try" %> to back

Hope it can help you..
Please let me know if you find any errors or problems when implement the codes.

Tag Cloud