Questions tagged [sinatra]

Sinatra is a Domain Specific Language (DSL) for quickly creating web applications in Ruby with minimal effort. It is an alternative to other Ruby web application frameworks such as Ruby on Rails, Nitro, Camping, and Rango.

Sinatra is a small and flexible designed and developed by Blake Mizerany (bmizerany) in California. The project was financed mainly by , and Engine Yard in the past and is now taken care of by .

It does not follow the typical model–view–controller pattern used in other frameworks; instead, Sinatra focuses on providing a small set of functionality to help you deal with common web tasks such as templates, routes, sessions, cookies and more.

Hello World with Sinatra:

require 'sinatra'

get '/hi' do
  "Hello World!"
end

Books:

Websites:

5369 questions
18
votes
4 answers

How to render a partial in sinatra view (haml in haml)?

I have a simple sinatra app that uses haml and sass for the views. One of the views (located in the views folder) is a partial for my navigation menu. I am trying to render it from index.haml but I get the following error: wrong number of arguments…
Ben
  • 225
  • 1
  • 3
  • 7
18
votes
4 answers

Installing a gem from Github with Bundler

I am trying to use the instructions here to install a pre-released version of a gem with bundler. The "bundle install" output lists the gem as getting installed, but "gem list" fails to find it. My Gemfile: source :gemcutter gem 'sinatra',…
18
votes
1 answer

How to start a Sinatra app using "run"

I tried to use a Gemfile in my Sinatra app, but when I launched my app I got this error: $ ruby config.ru config.ru:7:in `
': undefined method `run' for main:Object (NoMethodError) Here are my three files: hi.rb: get "/" do "Hello…
Simon
  • 619
  • 2
  • 9
  • 23
18
votes
10 answers

Develop iPhone app without a Mac?

Possible Duplicates: How can I develop for iPhone using a Windows development machine? I'm looking to build an iPhone app for my wife's phone, but am not interested in buying a Mac as a development platform for a one-off piece of work. The…
Dave
  • 391
  • 1
  • 4
  • 7
17
votes
5 answers

Sinatra access-control-allow-origin for sinatra public folder

How do I set up Sinatra so that static files in the public folder are returned with the response Access-Control-Allow-Origin = "*" ?
peter
  • 171
  • 1
  • 1
  • 3
17
votes
5 answers

sinatra helper in external file

I have lot of helpers in my main Sinatra project_name.rb and I want to remove them to the external file, what is the best practice to do that ? from ./preject_name.rb helpers do ...#bunch of helpers end to for exapmple…
equivalent8
  • 13,754
  • 8
  • 81
  • 109
17
votes
4 answers

Multiple Sinatra apps using rack-mount

I have a question regarding using rack-mount with Sinatra. I've got two classic-style Sinatra apps. Let's call one App defined in app.rb and the other API defined in api.rb. I would like it so that api.rb handles all routes beginning with '/api' and…
Michael Irwin
  • 3,119
  • 5
  • 24
  • 40
17
votes
4 answers

Ruby localization: i18n, g18n, gettext, padrino... - what's the difference?

Being somewhat new to Ruby I'm exploring existing libraries to do what I'd normally do in other scripting languages, and I'm a bit stumped by the localization libraries that might be available for something built on top of Sinatra/Sequel (Rails/AR…
Denis de Bernardy
  • 75,850
  • 13
  • 131
  • 154
17
votes
5 answers

Calling Sinatra from within Sinatra

I have a Sinatra based REST service app and I would like to call one of the resources from within one of the routes, effectively composing one resource from another. E.g. get '/someresource' do otherresource = get '/otherresource' # do something…
Stephen Petschulat
  • 1,159
  • 2
  • 14
  • 23
17
votes
1 answer

Automatic logging of DataMapper queries

I am working on a simple app in Sinatra with DataMapper. I want to see the queries that DM is created for my various chained finders, etc. I have tried: DataMapper::Logger.new(STDOUT, :debug) in my configure do ... end block in an environment.rb…
kEND
  • 7,379
  • 3
  • 19
  • 13
17
votes
1 answer

Restarting Sidekiq

What is the correct way to restart sidekiq. It seems to cache my workers' code when I start it, so every time I make a change to my workers I need to restart it. I'm doing this with Ctrl/C, but the process takes a long time to wind down and return…
Undistraction
  • 42,754
  • 56
  • 195
  • 331
17
votes
5 answers

Sinatra and Rack Protection setting

I am using Sinatra and CORS to accept a file upload on domain A (hefty.burger.com). Domain B (fizzbuzz.com) has a form that uploads a file to a route on A. I have an options route and a post route, both named '/uploader'. options '/uploader' do …
David Lazar
  • 10,865
  • 3
  • 25
  • 38
16
votes
5 answers

Deploy Sinatra app on Heroku

I have simple Sinatra app. web.rb: require 'sinatra' get '/' do "Hello" end Gemfile:* source :rubygems gem 'sinatra', '1.1.0' gem 'thin', '1.2.7' config.ru: require './web' run Sinatra::Application But when I deploy my app on Heroku I'll…
ceth
  • 44,198
  • 62
  • 180
  • 289
16
votes
3 answers

Get sinatra environment from within instance method

What's the proper way to determine the environment? Right now I'm using: class Main < Sinatra::Base get '/' do puts self.class.development? puts self.class.production? end end But it doesn't seem right.
pguardiario
  • 53,827
  • 19
  • 119
  • 159
16
votes
3 answers

How do I test a redirect in sinatra using rspec?

I'm trying to test for a redirect on the homepage in my sinatra app (more specifically, a padrino app), in rspec. I've found redirect_to, however it seems to be in rspec-rails only. How do you test for it in sinatra? So basically, I'd like something…
zlog
  • 3,316
  • 4
  • 42
  • 82