sinatra

Sinatra Mongoid String not valid UTF-8

Hi, I wrote this little application : require 'rubygems' require 'sinatra' require 'bson' require 'mongoid' Mongoid.configure do |config| name = "articles" host = "localhost" config.master = Mongo::Connection.new.db(name) config.persist_in_safe_mode = false end class Article include Mongoid::Document field :title field...

Problem With Routes After Deploying Sinatra Application

I wrote a simple Sinatra application with two "routes": "/show" and "/listshows". When I run the application on top of Webrick, everything works beautifully for both the static and non-static routes. Here are the URL's that I use: http://localhost:4567/listshows http://localhost:4567/show?guid=someguid Today, I deployed my simple ...

Shotgun problem with Sinatra - undefined methoddefault

I've been trying to run part of a Peepcode tutorial 'Meet Sinatra' with Shotgun (allows you to skip rebooting your web server for every change you make). The error threw up the following message: $ shotgun simple.rb /Library/Ruby/Gems/1.8/gems/shotgun-0.8/bin/shotgun:115: undefined methoddefault' for Rack::Handler:Module (NoMethodErro...

Accessing Rack middleware objects

Hi, I'm using Faye for pubsub along with Sinatra. Presently, I'm using Faye:RackAdapter in my config.ru like so: use Faye::RackAdapter, :mount => '/faye', :timeout => 45 I'd like to be able to add extensions to the instance of Faye::Server. I've tried to retrieve the server object and manipulate it from Sinatra, but it doesn't appea...

how to inject into sintra/haml?

I coded small web app that runs ant (batch file). The processing time of the batch file could take up to minutes. index.haml list all available ant files and run.haml runs them. The flow how it works now is that when I click a link from index.haml the ant script is run and after it finishes the whole run.haml page is sent to the browser...

Asynchronously iterating over the response of a request using Thin and Sinatra

If your response in Sinatra returns an 'eachable' object, Sinatra's event loop will 'each' your result and yield the results in a streaming fashion as the HTTP response. However, if there are concurrent requests to Sinatra, it will iterate through all the elements of one response before handling another request. If we have a cursor to ...

Datamapper validation errors with Sinatra

I'm trying to validate my Datamapper models and show the validation errors in my HAML template, I'm using Sinatra. I'm at loss how to save those errors into an instance variable and access them from my template. I've looked around for some documentation or tutorials explaining how to do something like this but I haven't been able to find...

RoR: Sinatra producing error "uninitialized constant"

I'm new to Ruby on Rails (formerly and currently PHP expert) so forgive my ignorance but I'm trying to get Sinatra working as middleware to redirect some old urls since I tried the gem rack-rewrite and couldn't get that to work either. I am using code samples from ASCIIcast so in my routes.rb I have the following: root :to => HomeApp ...

mailing list using JQuery, Sinatra, HAML fails with "undefined" email address

Somehow, a simple form I have to sign up for a mailing list (which adds an email to a Google Apps Group, using gdatav2rubyclientlib) seems to fail occasionally. The form is submitted via POST through jQuery, and the Sinatra app (running on nginx/Passenger) handles the POST and emails me a confirmation. Occasionally, I get emails that "...

does sinatra support all xmlhttp.readyState statuses?

my sinatra app returns only xmlhttp.readyState state 1 and 4. The Ajax request is processed and sinatra correctly returns its result. I wonder if I can get all xmlhttp.readyState states from sinatra. my sinatra code is like require 'rubygems' require 'sinatra' require "sinatra/reloader" require 'Haml' get '/index2?' do haml :...

SWIG: Ruby overloading problems

Hi, I have a sinatra web application and a C++ library that I can 'require' in sinatra (ruby) using bindings created by swig. I also have a second -very similar- library, in which the function names are partially the same as in the first one. When I require them both, the one that is loaded first 'wins', i.e. calls to the ambiguous fun...

sinatra app doesn't start on run

I'm on Ubuntu 10.10/Ruby 1.9.2 Whatever I do, I can't get a sinatra app to start on my local machine. hello.rb: require 'sinatra' get '/' do "Hello World!" end "$ ruby hello.rb" and "$ ruby -rubygems hello.rb" both result in a new prompt with no action taken. Any tips or pointers? ...

Heroku app fails to start - `require': no such file to load -- sinatratestapp (LoadError)

I'm trying to get my Heroku app to run using the bamboo-mri-1.9.2 stack. Of course it's running fine locally on Ruby 1.9.2. But when on production it crashes during the startup on executing config.ru which looks like this: require 'sinatratestapp' run Sinatra::Application My .gems file: sinatra --version '>= 1.0' And the applicatio...

rendering a partial from a haml file

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 (1 for 2) I am trying to render it with the following lines in index.haml .navigation ...

Sinatra requires restart

I'm just getting started with Sinatra. I'm running Ruby 1.9.2 on Ubuntu. After my first issue, I've run into another one: When I follow the simple sample application instructions at sinatra.rubyforge.org/doc/, I modify my source file, but the changes aren't apparent until I restart Sinatra - even though the tutorial mentions there is n...

How to test/spec Sinatra & MongoDB API with Cucumber?

I want to spec a Sinatra server that receives HTTP requests, stores things in MongoDB, and responds with JSON. How would I spec both the MongoDB entries and the responses? I'd like to use Cucmber and RSpec to do this cause I hear they're hot, but I'm not really good with them yet. Thanks! Matt ...

Sinatra vs. Rails

I've worked through some of the Sinatra and Rails samples, but I'm having a hard time figuring out which features belong to which technology. What specifically do I gain by using Sinatra/Rails? Is it just ActionPack/ActionView? Correct me if I'm wrong, but I COULD just use Webrick/Mongrel and serve up my .erb files right? And I could us...

uninitialized constant Tilt::CompileSite::Nokogiri error in sinatra/haml

I have a two line script that works nicely in ruby. I moved it to haml and getting the error NameError at / uninitialized constant Tilt::CompileSite::Nokogiri the haml code: %td - @doc = Nokogiri::XML(File.open(file)) = @doc.xpath("//testsuite").each_with_index {|node,index| "#{index+1}. #{node.attributes["name"]...

Active Record to_json\as_json on Array of Models

First off, I am not using Rails. I am using Sinatra for this project with Active Record. I want to be able to override either to_json or as_json on my Model class and have it define some 'default' options. For example I have the following: class Vendor < ActiveRecord::Base def to_json(options = {}) if options.empty? super ...

question marks in sinatra get method

I am trying to use a question mark in one of my url's but sinatra/ruby is interpreting it as the regex character that makes precedings optional. Is there any way to allow actual ? in your get methods? I have tried \? and [?] but they didn't work. Here is the begining of my get method: get '/group?groupid=:groupId' do |id| If I go to w...