sinatra

Problem pushing sqlite3 db to heroku: lib/taps/schema.rb:30:in `sqlite_config': undefined method `[]' for nil:NilClass (NoMethodError)

I have a Sinatra DataMapper app hitting a sqlite3 database that I am attempting to deploy to Heroku. First pass, I included my database file in the git repo. This works, as in the app runs, but production data does not belong in the repository. It doesn't really work though because the database is read-only. I then removed the db fil...

mutidimensional array from javascript/jquery to ruby/sinatra

Hi, how do I pass a 2-dimensional array from javascript to ruby, please? I have this on client side: function send_data() { var testdata = { "1": { "name": "client_1", "note": "bigboy" }, "2": { "name": "client_2", "note": "smallboy" } } consol...

How does one access all form fields in Sinatra?

Sinatra makes it easy to access any particular incoming form field by name: post "/" do params['form_field_name'] end But how does one enumerate over all the form fields in a request? I found nothing in the documentation. I even tried request.body.split('&') but request.body is an instance of StringIO, and not a string. ...

MySQL connection timeout - MySQL server has gone away (Sinatra, ActiveRecord)

Hi, Here is an outline of my app: require 'sinatra' require 'active_record' ActiveRecord::Base.establish_connection( :adapter => "mysql", host => $DB_HOSTNAME, :database => $DB_NAME,:username => $DB_USERNAME,:password => $DB_PASSWORD) class Sometable < ActiveRecord::Base end get '/' do #stuff with Sometable end # a lot ...

Automatically Refreshing Rails Metal In Development Mode

I am trying to develop a rails metal endpoint using sinatra, but is proving to be a pain because I have to restart the server every time I change the code. I am in Jruby and running from within a larger Java app. Is there an easy way to make this code refresh for every request? ...

How to setup a self contained project running jetty+sinatra+jruby?

I already installed jruby and gems seems to be installed nicely under jruby's directory so I don't have to worry about that. Now I would like to be able create a sinatra application and run it on top of jetty or some other efficient standalone server? What do you recommend? It would be important for me that the application source can be...

jquery post to webrick via sinatra only works in IE

When I run my little test app in IE, the log output from webrick shows a return code of 200, and indicates it received a post request: 192.168.0.18 - - [03/Nov/2009 16:17:37] "POST /testpost HTTP/1.1" 200 512 0.0010 Quietspeed.example.com - - [03/Nov/2009:16:17:37 EST] "POST /testpost HTTP/1.1" 200 512 - -> /testpost And the page is up...

Unable to output MySQL tables which involve dates in Sequel

I'm trying to use Sequel to access a MySQL database in Ruby. When I try accessing a table which involves a date column, I am presented with an error. When I access a table without, it functions fine. What is wrong? Example Code: require 'rubygems' require 'sequel' DB = Sequel.connect(:adapter=>'mysql', :host=>'localhost', :database=>'...

Ruby 1.9 encoding problems with Sinatra and Rack

For giggles I tried to start my blog using ruby 1.9. All the gems compile and work, but I crank it up and open it in a browser, I get this: Many newlines I haven't found any useful information regarding this. Code for the application is located here ...

Ruby, Sinatra and Closing Connections

Does anyone know if there is a way to prevent sinatra from sending the 'Connection: close' header in its responses? To be clear, I have a very simple get '/path' do puts "Some (~200 byte long) string" end But on putting the output through a network analyser I see its sending the Connection: close header straight after the HTTP/1.1 ...

Ruby, Sinatra and Streaming

I'm furiously trying to debug why iTunes isn't accepting the data I'm sending to it (as a DAAP Server) - you can see what I'm trying to do on the github page. The only difference I can find between my response and an identical response from mt-daapd (which iTunes does accept) is that the mt-daapd response is broken down into small packe...

How can I randomize DataMapper collection and convert it to JSON?

Hi, I'm pulling my hair out trying to build a little random photo JSON feed using DataMapper/Sinatra. Here's what I have so far.. Photo.favorites.to_json(:methods => [:foo, :bar]) So that works fine. The to_json method is provided in the dm-serializer library. All I want to do is randomize that feed so the photos don't show up in the...

Sinatra + Bundler ?

I'm wondering how a one can use Bundler with Sinatra. The idea is to use the gems that Bundler downloads inside the .gems folder. ...

newbie sinatra question

To return a file using sinatra, I had been using this: get '/:name' do x = File.open('c:/mywebsite/' + params[:name],'r') end where the incoming url is "http://localserver:4567/myfile.html. It works, but it occurs to me there must be a better way, yet I can't find the preferred mechanism on the sinatra site. ...

Can I protect with a .htaccess file some routes with sinatra?

I wrote a small app with Sinatra and have some admin routes (/admin/new, admin/edit/2, ...) and want to protect them with a .htaccess prompt. Can somebody tell me how I do that? ...

How to handle POSTed XML via Sinatra Ruby app

I'm planning on using Sinatra for a new tiny webservice (WS) that I need to put together for a client. The WS will only have two methods, one accessed via GET and one via POST. For the POST method, the client will send an XML packet to the sinatra WS which will parse the data and issue either a 200 OK HTTP response or a 40x error code....

Ruby & Datamapper checking if a record exists, and where?

I have a basic Ruby app that I am building with Sinatra, Datamapper and has user authentication using OAuth. When I receive the data back from the Oauth service, I save a record of a new user in an sqlite3 db. What I don't know how to do is how to go about verifying the user record doesn't already exist on the user database table. I ca...

Using Sinatra and MongoDB - what's the recommended way to "keep alive" the mongodb connection between http requests?

I've used ASP.NET and now I'm working on a Sinatra/MongoDB app. With ASP.NET architecture, the connection to the database a given request uses comes from a pool of connections that the ADO.NET manages. The connections are kept alive in the pool between requests so that the cost of building and tearing down the connection isn't paid f...

Ruby Sinatra - Add custom routes for files in Public folders.

Hi, I've a Sinatra app which would be used by different clients. I wish to show the client's Company Logo and a custom layout.erb for each client. The code base is essentially same for everyone. All I need is a way to easily maintain a different set of files in the 'Public' directory and 'layout.erb', and when deploying to the remote ...

Sinatra on Rack under Passenger returning 0-byte pages

I'm trying to write a Sinatra app that will run on a shared Passenger server. For now, I'd be happy just getting a "hello world", but something isn't working quite right. I have: config.ru require 'vendor/sinatra-lib/sinatra.rb' set :environment, :production disable :run require 'myapp.rb' run Sinatra::Application myapp.rb get '/...