Created
June 28, 2012 08:26
-
-
Save leucos/3009889 to your computer and use it in GitHub Desktop.
Using provide for some actions only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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