ShortRails
URL shortener for Rails.
Installation:
Add this line to your application's Gemfile:
gem 'short_rails'
And then execute:
$ bundle
Or install it yourself as:
$ gem install short_rails
Configuration
Mount engine in config/routes.rb
Rails.application.routes.draw do
mount ShortRails::Engine => "/s"
end
Copy engine migrations to application
$ rake short_rails:install:migrations
$ rake db:migrate
Run standalone dummy app
$ cd test/dummy/
$ rails s
http://localhost:3000/s
Usage
POST /s submit data:
- 'base_url': base URL without parameters (e.g. "http://example.com/path")
- 'base_url_short_param': optional parameter for short id on redirect (e.g. "s")
- url parameters
returns short id (e.g. 'abc123')
GET /s/abc123 if 'base_url_short_param' has been set, redirect to
"
? = " (e.g. "http://example.com/path?s=abc123") else redirect to full URL
GET /s/abc123/params get full URL parameters as JSON
GET /s/abc123/qrcode parameters:
- 'width' (optional): image width (max 2048), will be clamped to minimum QR code width
- 'height' (optional): image height (max 2048), will be clamped to minimum QR code height
get QR code as PNG image