SinatraSimpleRouter
Simple routing abstraction for Sinatra applications.
Installation
Add this line to your application's Gemfile:
gem 'sinatra_simple_router'
And then execute:
$ bundle
Or install it yourself as:
$ gem install sinatra_simple_router
Usage
require "sinatra"
require "sinatra_simple_router"
class UsersController < SinatraSimpleRouter::Controller
def show
@user = User.find(params[:id])
erb :"users/show"
end
def update
@user = User.find(params[:id])
@user.update_attributes(params[:user])
redirect "/users/#{@user.id}"
end
end
class ItemsController < SinatraSimpleRouter::Controller
def show
@item = Item.find(params[:id])
render json: @item
end
end
class Application < Sinatra::Base
include SinatraSimpleRouter
match :get, "/users/:id", UsersController, :show
match :patch, "/users/:id", UsersController, :update
match :get, "/items/:id.json", ItemsController, :show
end
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request