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...
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 =...
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.
...
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.
...
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...
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/...
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...
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 %> ...
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...
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...
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...
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!
...
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...
Is there a way to get a Django Admin style web-admin for 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", "...
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 ?
...
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...
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...
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 ...
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 ...