Saturday, June 13, 2015

Melodiest 0.4.0 Has Been Released

Melodiest version 0.4.0 have been released few days ago. The main difference version 0.4.0 with previous version is the generator.

Changes since 0.3.0

  • add SQL logger in development environment
  • generate public directory when generating application
  • add tux to Gemfile. Use tux as Sinatra console
  • when has no option, melodiest command will use --help as default option

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'