sinatra

Sinatra/Rails: Persisting custom class instances during app lifetime

Can I assert rails/sinatra apps are initialized only once and all requests share the same app instance? or do new requests spawn new app instances? Is it possible to instance custom classes and persist them during app lifetime without using sessions, database storages or third party services? If so, what are the implications from a thr...

Concurrent web requests with Ruby (Sinatra?)?

I have a Sinatra app that basically takes some input values and then finds data matching those values from external services like Flickr, Twitter, etc. For example: input:"Chattanooga Choo Choo" Would go out and find images at Flickr on the Chattanooga Choo Choo and tweets from Twitter, etc. Right now I have something like: @images =...

How to do a Post/Redirect/Get using Sinatra?

What's Sinatra's equivalent of Rails' redirect_to method? I need to follow a Post/Redirect/Get flow for a form submission whilst preserving the instance variables that are passed to my view. The instance variables are lost when using the redirect method. ...

How do I write an extension for Sinatra without packaging it as a gem?

I want to include the distance_of_time_in_words method in a sinatra app I don't want to package and distribute a gem, which is what the Sintra docs direct you to do. I just want that method accessible in my view. What's the easiest way to do this? Thanks. ...

Ruby w/ Postgres & Sinatra - Query won't order right with parameter??

So I set a variable in my main ruby file that's handling all my post and get requests and then use ERB templates to actually show the pages. I pass the database handler itself into the erb templates, and then run a query in the template to get all (for this example) grants. In my main ruby file: grants_main_order = "id_num" get '/gran...

Error in requiring Sinatra gem

I'm having a hard time getting Sinatra running on my local setup, Ubuntu Karmic 9.10. The error getting thrown when I have require 'sinatra' is: NoMethodError: undefined method `[]' for nil:NilClass from /usr/local/lib/ruby/gems/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:891:in `compile' from /usr/local/lib/ruby/gems/1.8/gems/sinatra-1.0/...

How can I delete a file in Sinatra after it has been sent via send_file?

I have a simple sinatra application that needs to generate a file (via an external process), send that file to the browser, and finally, delete the file from the filesystem. Something along these lines: class MyApp < Sinatra::Base get '/generate-file' do # calls out to an external process, # and returns the path to the gene...

Relative path issue within Sinatra view

I am using the following code to check existence of a file before publishing an image in my erb file. This is a ruby/sinatra app - not rails. <% @imagename = @place.name + ".jpg" %> <% if FileTest.exist?( "/Users/Tim/projects/game/public/" + @imagename ) %> <p><img src= '<%= @imagename %>' width="400" height="300" /> </p> <% end %> ...

Displaying large forms on the iPhone

I'm currently in the process of toying with a few things at the same time: Heroku, Sinatra, HAML/SASS, and of course the glue: Ruby. I'm loving that, and it all goes well with DataMapper. However, my current "project to learn by" seems to be pretty data-intensive. Though it is also something I want to have. I've been a bit of an amat...

Error message when running a Sinatra application on Windows Vista.

I was following a video tutorial by Adam Keys about how to make a URL shortener app in Sinatra. The code that is giving me problems is located here http://pastie.org/958644 So when I ran it I got this error: shortener.rb:12: syntax error, unexpected $undefined, expecting $end @@ home I typed it exactly as Adam said but this keeps happ...

Errors with shotgun gem and msvcrt-ruby18.dll when running my Sinatra app

Greetings, Every time I make a change to a Sinatra app I'm working on and try to refresh the browser (located at http://localhost:4567/) the browser will refresh and, the console window seems to restart the WEB brick server. The problem is that the content in the browser window does not change. A friend of mine told me it was a shotgu...

In Sinatra - does anyone use test fixtures? how is your test suite set up?

I'm coming from a Ruby/Rails world. I'm getting testing set up on a Sinatra project (with Rack::Test). I usually use Fixtures in testing. Is there an equivalent for Sinatra? How do people set up their Sinatra test suites (outside of the basic helloworld example that is the only example I can find for Sinatra tests). Thanks! ...

Why is this RMagick call generating a segmentation fault?

I've been banging my head against the wall for the better part of an hour trying to figure out what's going wrong here, and I'm sure (or rather hoping) it's something fairly obvious that I'm overlooking. I'm using Ruby 1.9.1, Sinatra 1.0, and RMagick 2.13.1. ImageMagick and RMagick are correctly installed and functional—I've successfully...

Sinatra Web Admin (like Django Admin)

Is there a way to get a Django Admin style web-admin for Sinatra? ...

undefined method get with sinatra

I have following code require 'rubygems' require 'sinatra' get '/' do 'Hello World!' end gem list sinatra *** LOCAL GEMS *** sinatra (1.0, 0.9.4) ruby -v ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.2.0] Error ruby myapp.rb ["==", "===", "=~", "__id__", "__send__", "class", "clone", "display", "dup", "enum_for", "...

How can I test helpers blocks in Sinatra, using Rspec ?

I'm writing a sinatra app and testing it with rspec and rack/test (as described on sinatrarb.com). It's been great so far, until I moved some rather procedural code from my domain objects to sinatra helpers. Since then, I've been trying to figure out how to test these in isolation ? ...

Issues with Sinatra and Heroku

So I've created and published a Sinatra app to Heroku without any issues. I've even tested it locally with rackup to make sure it functions fine. There are a series of API calls to various places after a zip code is consumed from the URL, but Heroku just wants to tell me there is an server error. I've added an error page that tries to g...

learning and "singing" Ruby with Sinatra

Hello I'm trying to improve my ruby knowledge by reading The Ruby Programming Language book. Reading Coders at work I saw that lot of the interviewees suggest to dive into a project source code to learn best practices to be aware of bad habits and of course to take new inspirations for how to do things. I decided to pick a project as...

What is the best way to handle dynamic content_type in Sinatra

I'm currently doing the following but it feels "kludgy": module Sinatra module DynFormat def dform(data,ct) if ct == 'xml';return data.to_xml;end if ct == 'json';return data.to_json;end end end helpers DynFormat end My goal is to plan ahead. Right now we're only working with XML for ...

Rack::ResponseHeaders in rackup for Sinatra

I think this is a very easy one, but I can't seem to get it right. Basically, I'm trying to use Rack middleware to set a default Cache-Control header into all responses served by my Sinatra app. It looks like Rack::ResponseHeaders should be able to do exactly what I need, but I get an error when attempting to use the syntax demonstrated ...