Padrino

Advanced Usage

3rd Party Plugins

Padrino is a modular framework. As such, you can leverage other libraries such as Sinatra libraries which complement Padrino quite well.

Rendering JSON with sinatra-contrib

First you must reference sinatra-contrib in your Gemfile:

# Gemfile

source 'https://rubygems.org'

# Project requirements
gem 'rake'

# Component requirements
gem 'haml'

# Test requirements

# Padrino Stable Gem
gem 'padrino', '0.13.1'

# Or Padrino Edge
# gem 'padrino', :github => 'padrino/padrino-framework'

# Or Individual Gems
# %w(core support gen helpers cache mailer admin).each do |g|
#   gem 'padrino-' + g, '0.13.1'
# end

gem 'sinatra-contrib'

You may use the #json method after you have registered the sinatra helper:


module MyJsonApp
  class App < Padrino::Application
    register Padrino::Mailer
    register Padrino::Helpers

    helpers Sinatra::JSON

    enable :sessions

    get '/' do
      hash = {foo: 'bar'}
      json hash
    end
  end
end

last updated: 2016-09-04

comments powered by Disqus