rack

Override default route if no parameter specified

Consider the following snippet: get '/hello/:name' do |n| "Hello #{n}!" end How can I set a default parameters if name isn't specified? If I can set the default paramater to Tom will this also route the URL so /hello/ will automatically redirect to /hello/tom? ...

Rails 3 as Rack middleware

Since Rails is fully compliant with Rack I was wandering how I would set up a rackup file so that a Rails application is just a piece of middleware and then a request could hit another app further down the middleware stack. What I really want is to use a Rails app to handle authentication and authorization for smaller rack-apps later on...

HTML encode UTF-8 string gets mangled into latin1

I'm parsing my nginx logs, and I want to discover some details from the HTTP_REFERER string, for example, the query string used to find the web site. One user typed in "México" which gets encoded in the log as "query=M%E9xico". Passing this through Rack::Utils.parse_query('query=M%E9xico') you get a hash, {"query" => "M?xico"} When you...

Is there anyway to make a Rails / Rack application tell the web server to drop the connection

There are many security reasons why one would want to drop an HTTP connection with no response (eg. OWASP's SSL best practices). When these can be detected at the server level then it's no big deal. However, what if you can only detect this condition at the application level? Does Rails, or more generally Rack, have any standard way o...

android/rails multipart upload problem

My problem is that I try to upload an image and some text values to an rails server, and the text values end up as files, insted of just param values. How the post looks on the server Parameters: {"action"=>"create", "controller"=>"problems", "problem"=>{"lon"=>#File:/tmp/RackMultipart20100404-598-8pi1vj-0>, "photos_attributes"=>{"0"=...

Ruby Rack: startup and teardown operations (Tokyo Cabinet connection)

I have built a pretty simple REST service in Sinatra, on Rack. It's backed by 3 Tokyo Cabinet/Table datastores, which have connections that need to be opened and closed. I have two model classes written in straight Ruby that currently simply connect, get or put what they need, and then disconnect. Obviously, this isn't going to work long...

Is Rails Metal (& Rack) a good way to implement a high traffic web service api?

I am working on a very typical web application. The main component of the user experience is a widget that a site owner would install on their front page. Every time their front page loads, the widget talks to our server and displays some of the data that returns. So there are two components to this web application: the front end UI ...

Post request with body_stream and parameters

Hello, I'm building some kind of proxy. When I call some url in a rack application, I forward that request to an other url. The request I forward is a POST with a file and some parameters. I want to add more parameters. But the file can be quite big. So I send it with Net::HTTP#body_stream instead of Net::HTTP#body. I get my request a...

How do I make Rack::Reloader re-load changes to haml files?

My jruby rack sinatra compass haml app correctly reloads changes to *.rb files, but does not detect changes to *.haml files. Is this compass doing some caching or a limitation of Rack::Reloader? Any pointers to how to fix? ...

Getting Rails Application Running Under IronRuby Rack

Anyone else playing with ironruby? I have successfully got the IronRuby.Rails.Example project running on my local machine under IIS 5.1. I am now attempting to get my own demo rails site running in the same way. My web.config is slightly different from the example project. I am attempting to only use what was distributed with IronRuby...

Issues loading IronRuby.Rack assembly

I'm trying to get IronRuby on Rails running with iis7 server 2k8 and can only get as far as it cannot load the assembly 'IronRuby.Rack' (Screen Shot: http://grab.by/3VZm) has anyone gotten this working? Any tips you can give me? Thanks, -CJ ...

How do I pass a cookie to a Sinatra app using curl?

I'm using the code from the example titled "A Slightly Bigger Example" from this tutorial http://rubylearning.com/blog/2009/09/30/cookie-based-sessions-in-sinatra/ to figure out how to send a cookie to a Sinatra application but I can't figure out how to set the values correctly When I set the name to be "brandon" in the application it c...

Thin, Sinatra, and intercepting static file request to do CAS authentication

I'm using the casrack-the-authenticator gem for CAS authentication. My server is running Thin on top of Sinatra. I've gotten the CAS authentication bit working, but I'm not sure how to tell Rack to intercept "/index.html" requests to confirm the CAS login, and if the user is not allowed to view the page, return a HTTP 403 response inst...

How does RoR's reloading content on refresh work?

RoR allows you to, as long as the env is development, change parts of the your application code and then just refresh the browser--and everything is changed, without having to restart Mongrel. How does this work, and where in the Rails codebase is this done? (Or, alternatively, is there some easy way to do this with Rack+Mongrel?) Tha...

How do I serve a binary file through rack?

I think I'm being a bit silly here, but I keep getting errors complaining about the SERVER_NAME key missing from the env hash, and I can't find any substantial documentation on Rack::SendFile.. so- how do I serve up files? ...

nginx + passenger not using rackup file

I have an issue where Passenger is not detecting the config.ru file for the following nginx server server { listen 80; passenger_enabled on; server_name callumj.com cjlondon.com; access_log logs/callumj.access.log; root /webapps/callumj_com/public; } Nginx just seems to ignor...

Access Rails 3 Session from Rack?

I was able to do the following in Rails 2.3.5 to access attributes that I set on the session from within my Rails app. Now in Rails 3, env["rack.session"] is nil. How do I do the same thing in Rails 3? class CallbackFilter def initialize(app) @app = app end def call(env) unless env["rack.session"][:oauth_callback_method...

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! ...

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 ? ...

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 ...