Skip to content

Instantly share code, notes, and snippets.

@delagoya
Created December 8, 2008 14:42
Show Gist options
  • Save delagoya/33471 to your computer and use it in GitHub Desktop.
Save delagoya/33471 to your computer and use it in GitHub Desktop.
Setting session cookies from flash in Merb
This is Merb middleware to set a session cookie when the request comes from flash.
You must first require the module, then invoke it's use in the call chain in either rack.rb or config.ru.
Examples below. Note that SWFUPload by default adds a lot of post parameters with non-standard
ruby variable names, so merb-action-args will choke a bit on that unless you customize SWFupload
or just not use action-args.
Also note that the session information must be set as a GET parameters, e.g. in the URL request like so:
SWFUpload.onload = function () {
var settings = {
flash_url : "/flash/swfupload.swf",
file_post_name: "attachment",
upload_url: "#{url(:upload_attachments,@attachment)}?_session_id=#{cookies[:_session_id]}",
...
## Phusion passenger rack up file, as an alternate to the Merb's rack.rb
## ... other code
Merb::BootLoader.run
use Merb::Rack::SwfSetSessionCookie, Merb::Config[:session_id_key]
run Merb::Rack::Application.new
## Merb rack.rb file, set the use of this middleware. Make sure it has been required already
## ... other code ...
use Merb::Rack::SwfSetSessionCookie,Merb::Config[:session_id_key]
run Merb::Rack::Application.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment