Sunday, May 24, 2015

Introducing Melodiest

Recently I have a plan to build very small personal web applications using Ruby. My choice is using Sinatra. Why? Using Ruby on Rails is too big for my projects. Using Padrino is still too big for my projects.

So I decide to create Melodiest as generator for each my projects. The goal is to generate Sinatra application with minimalist code and configuration.

Monday, October 13, 2014

Route Globbing In Ruby on Rails

Route globbing is a way to specify parameter from request should be matched to all remaining parts of a route. For example in Rails 4:

get 'users/*xyz' => 'users#list'

When client send GET request with URL '/users/foo/bar', Rails will automatically match to action list in controller users with params[:xyz] equals 'foo/bar'. The fragments prefixed with a star are called "wildcard segments".

Wildcard segments can contain request format. For example, By requesting '/users/foo/bar.json', params[:xyz] will equals 'foo/bar' with request format of JSON. If you want to make the format segment must be exist, in config/routes.rb you can supply format: true like this:

get 'users/*xyz' => 'users#list', format: true

A route have more than one wildcard segments. Wildcard segments can be anywhere and can combine with other parameters. For example:

get '*abc/users/*xyz/:username' => 'users#list'

So, if client make GET request to '/yuhuu/woohoo/users/foo/bar/example' as the result params[:abc] equals 'yuhuu/wohoo', params[:xyz] equals 'foo/bar', and params[:username] equals 'example'

Sunday, April 13, 2014

Linkedin Share Button in Rails 4 with Turbolinks Enabled

While implementing Linkedin share-button on my Rails 4 application with Turbolinks enabled, I encounter problem how to reload Linkedin share-button correctly because my code always showing "duplicate in.js loaded, any parameters will be ignored".