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
22
votes
4 answers

How to pass an argument when calling a view file?

I wrote a webform using Sinatra and Haml that will be used to call a Ruby script. Everything seems fine except for one thing: I need to pass an argument to a Haml view file from the Sinatra/Ruby script. Here is a part of my code: #!/usr/bin/env…
Cocotton
  • 910
  • 2
  • 7
  • 22
22
votes
4 answers

Devise with Sinatra

Does anyone had installed Devise gem with Sinatra? Devise is based on Warden and so it should work on Sinatra, I couldn't find any related info about how to implement it.
Martin
  • 11,216
  • 23
  • 83
  • 140
22
votes
4 answers

Running Sinatra on port 80

I installed Sinatra and it works but it uses port 4567 by default. I want it to run on port 80. In an effort to get it to work on port 80, I tried this: require 'rubygems' require 'rack/handler/webrick' require…
Jason Swett
  • 43,526
  • 67
  • 220
  • 351
22
votes
4 answers

Streaming data from Sinatra/Rack application

I am trying to stream textual data (XML/JSON) from a Ruby (1.9.1p378) Sinatra (1.0) Rack (1.2.1) application. The suggested solutions (e.g. Is there a way to flush html to the wire in Sinatra) do not seem to work - the server just blocks when I…
yawn
  • 8,014
  • 7
  • 29
  • 34
22
votes
4 answers

"CSRF detected" with Omniauth and Google

I'm getting this OmniAuth::Strategies::OAuth2::CallbackError at /auth/google/callback csrf_detected | CSRF detected My code: require 'sinatra' require "sinatra/json" require "sinatra/config_file" require 'omniauth-oauth2' require…
Joseph Le Brech
  • 6,541
  • 11
  • 49
  • 84
22
votes
2 answers

Return empty body with Sinatra

How can I specify sinatra to return an empty body with status of 200? I can do body "" but is there a more explicit way of doing this?
0xSina
  • 20,973
  • 34
  • 136
  • 253
22
votes
1 answer

Undefined method `bytesize' for #

I'd like to store and update blogger labels to datastore in GAE. When I run that code, I get this error: javax.servlet.ServletContext log: Application…
tknv
  • 562
  • 1
  • 6
  • 23
21
votes
4 answers

How to get ALL of the URL parameters in a Sinatra app

Using the following Sinatra app get '/app' do content_type :json {"params" => params}.to_json end Invoking: /app?param1=one¶m2=two¶m2=alt Gives the following result: {"params":{"param1":"one","param2":"alt"}} Params has only two keys,…
necrobious
  • 305
  • 1
  • 3
  • 8
21
votes
1 answer

"puts" output not displaying in Heroku logs for Sinatra app

I'm trying to use "puts" to test a few things with a Sinatra app that's hosted on Heroku. Interestingly, the output seems to queue up and only displays upon restarting the Heroku dyno. I've tried with 'Thin' and 'Webrick', but have the same…
dougiebuckets
  • 2,383
  • 3
  • 27
  • 37
21
votes
1 answer

How do I do html forms with sinatra?

Is there some utilities available so that I could easily encapsulate form fields passed in requests in an object or do I have to create it myself by parsing fields from params in every request?
JtR
  • 20,568
  • 17
  • 46
  • 60
20
votes
3 answers

Pass arguments to new sinatra app

Simple question: I want to be able to pass options into my sinatra app in config.ru. How is that possible? My config.ru looks like this: run MyApp But I want to have this in my MyApp class to take arguments: class MyApp < Sinatra::Base def…
Ronze
  • 1,544
  • 2
  • 18
  • 33
20
votes
3 answers

What are the main differences between Sinatra and Ramaze?

I'm looking for a lightweight Ruby web framework and have come across Sinatra and Ramaze. Both seem extemely light, concise and simple. But I don't know enough about either to say what the main distinctions are. Perhaps someone with experience with…
Yen
  • 2,176
  • 3
  • 19
  • 27
20
votes
5 answers

Sending a DELETE request from Sinatra

I am trying to develop a RESTful Sinatra application. Now, I know how to respond to a delete request with something like delete '/user/:id' do |id| #do something in the model end What I am interested in is how do I get to execute that method. I…
sebastiangeiger
  • 3,386
  • 7
  • 29
  • 37
20
votes
2 answers

How to make a layout template in Sinatra?

I'm new to Sinatra and I can't figure out where to put my application layout. I've seen the inline method that uses # app code __END__ @@layout %html = yield But I'd like the layout to be in it's own .haml file. What should the layout…
maček
  • 76,434
  • 37
  • 167
  • 198
20
votes
5 answers

Rails 3 vs Sinatra

For my next web application, I'm debating whether to use Rails 3.x or Sinatra. I would like to use the server to provide user authentication, application-triggered emails, a fairly complex data model (behind ActiveRecord), and a JSON data interface…
Jay Godse
  • 15,163
  • 16
  • 84
  • 131