Skip to content

Instantly share code, notes, and snippets.

@leucos
Created June 28, 2012 08:26
Show Gist options
  • Select an option

  • Save leucos/3009889 to your computer and use it in GitHub Desktop.

Select an option

Save leucos/3009889 to your computer and use it in GitHub Desktop.
Using provide for some actions only
require 'ramaze'
# Put a jpeg in the same directory as this file named 'image.jpg"
# calling index.jpg will yell at user
# calling send_image.jpg will send back image.jpg
class MyController < Ramaze::Controller
map '/'
provide(:jpg, :type => 'image/jpeg') do |action, value|
if ["send_image", "mustachify"].include? action.method
# do whats good to send image
open(value,'rb').read if File.file? value
else
Ramaze::Log.info("User sucked and asked jpeg for %s" % action)
action.options[:content_type] = "text/plain"
action.method_value = "Man you suck at getting URls"
end
end
def index
end
def send_image
"image.jpg"
end
end
Ramaze.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment