Last Updated: February 25, 2016
·
1.119K
· shime

Sinatra-like routes in your Rails controllers

Have you ever built an API in Rails app? How did you do it?

Have you seen how expressive Sinatra is when it comes to URL => action matching?

I really like it more than Rails when it comes to building an API.

This

get "/api/greet" do
   render :text => "hello"
end

Instead of this

# in config/routes.rb
get "/api/greet"

# in app/controllers/api_controller.rb
def greet
    render :text => "hello"
end

I was, however, missing all the methods Rails provides for controller actions. That's why I decided to build something that makes controller actions look like Sinatra, but behave like Rails.

Sounds cool? Check out Sinatrify, a gem that enables just this. It's small and you should easily get to know what's going on.

Let me know what you think!