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

No such file or directory - getcwd

I uploaded my Sinatra app to Beanstalk. When I go to my site my logs are returned No such file or directory - getcwd The app was working before. I believe the issue has to do with the fact that I added SASS to my app, but I'm not positive. In my…
thank_you
  • 11,001
  • 19
  • 101
  • 185
27
votes
3 answers

How to raise a custom error code in sinatra?

I did the following in my sinatra app: disable :show_exceptions disable :raise_errors error do haml :error, :locals => {:error_message => request.env['sinatra.error'].to_s} end get '/error' do raise "ERROR!!" end If I visit /error I get a 500…
le_me
  • 3,089
  • 3
  • 26
  • 28
27
votes
3 answers

Sinatra controller params method coming in empty on JSON post request

I've got a Sinatra app and in most of my controllers json comes in and is picked up automatically in the params object. However, I've got a post action that doesn't get the params at all unless I play a trick with a before method to pull the…
jaydel
  • 14,389
  • 14
  • 62
  • 98
26
votes
2 answers

Deleting the current session with Rack::Session::Cookie

I feel like I'm missing something obvious here, and I'm hoping that as soon as I post this someone will shame me with the google search link I was missing :-) enable :sessions get '/logout' do # What goes here to kill the session? end
ecoffey
  • 3,423
  • 4
  • 23
  • 22
26
votes
8 answers

Specifying Content Type in rspec

I'm trying to build an rspec test that sends JSON (or XML) via POST. However, I can't seem to actually get it working: json = {.... data ....}.to_json post '/model1.json',json,{'CONTENT_TYPE'=>'application/json'} and this json = {....…
skeevis
  • 261
  • 1
  • 3
  • 3
26
votes
2 answers

How do I set up a Sinatra app under Apache with Passenger?

Let's say I have the simplest single-file Sinatra app. The hello world on their homepage will do. I want to run it under Apache with Phusion Passenger, AKA mod_rails. What directory structure do I need? What do I have to put in the vhost conf…
kch
  • 77,385
  • 46
  • 136
  • 148
25
votes
8 answers

Sinatra success stories

Have you used Sinatra successfully? What kind of a project was it? In what situations would you recommend using Sinatra instead of Rails or Merb?
Antti Tarvainen
  • 1,209
  • 12
  • 14
25
votes
1 answer

What python equivalent of Sinatra would you recommend?

I like the sinatra framework, but might have to work in python. A quick web search has uncovered a few python equivalents including itty, flask and juno. I'd like to know people's experience of these, or other sinatra equivalents. Which would you…
Hamish Downer
  • 16,603
  • 16
  • 90
  • 84
24
votes
4 answers

How to protect the 'public' part of a REST service from spam?

I have a REST service that's reasonably complete and will be used with an iOS app. It's built using Ruby/Sinatra but I don't think that really matters here. I'm using HTTP Basic Authentication over SSL for various endpoints and that part is working…
Riaz
  • 423
  • 2
  • 6
  • 15
24
votes
5 answers

How mix in routes in Sinatra for a better structure

I found nothing about how I can mix-in routes from another module, like this: module otherRoutes get "/route1" do end end class Server < Sinatra::Base include otherRoutes get "/" do #do something end end Is that possible?
roundrobin
  • 674
  • 1
  • 7
  • 23
23
votes
3 answers

Mount Sinatra app inside a rails app and sharing layout

I would like to mount a sinatra application in my rails app. But I would like this one to share the same layout. The iframe could work but do you have any other idea ? Thanks
Mike
  • 5,165
  • 6
  • 35
  • 50
23
votes
3 answers

How do I set HTTP Headers in Ruby/Sinatra app, hosted on Heroku?

I've got a working app based in Ruby and Sinatra that is deployed on Heroku. I want to take advantage of the HTTP caching available on Heroku, which uses Varnish. I'm not sure what the best way to set the headers is, and the correct syntax. Any…
Neil
  • 297
  • 1
  • 2
  • 5
23
votes
2 answers

How to dump an HTTP request from within Sinatra?

Is there a way to dump all incoming requests to a Sinatra application in the exact way the application receives the data? Maybe some sort of Rack middleware?
t6d
  • 2,595
  • 3
  • 26
  • 42
23
votes
3 answers

Access Ruby hash variables

I am pretty new to ruby and sinatra but basically I have this route: put '/user_list/:user_id' do puts request.params["model"] end and it returns the…
Blaine Kasten
  • 1,633
  • 1
  • 15
  • 27
23
votes
5 answers

Why should one use a http server in front of a framework web server?

Web applications frameworks such as sinatra (ruby), play (scala), lift (scala) produces a web server listening to a specific port. I know there are some reasons like security, clustering and, in some cases, performance, that may lead me to use an…
juanpavergara
  • 1,511
  • 1
  • 11
  • 22