This blog post was very useful to figuring it out.
Let's suppose you have a database model Image and an Images controller and action 'show'. Firstly at the end of your merb_init.rb file, put the following line:
Merb.add_mime_type(:jpg, :to_jpg, %w[image/jpeg], {})then in the controller add a provides parameter for jpg and
In your model add a method to_jpg like so.
def to_jpeg
data
end
Where data is the name of the column in your images table that holds the binary data.
Make sure you restart your server after all these changes.
Next your controller should look something like this:
class Image < Application
provides :xml, :js, :yaml, :jpg
def show
image = Image.find(params[:id])
render image
end
end
And thats it! If you go to /images/1.jpg (assuming RESTful routing...), the controller will retrieve the image with id 1 and MERB will call the to_jpg method on that object. It will then output that binary image data and send with the correct http header Content-Type parameter.
3 comments:
super viagra pro splitting viagra viagra and cialis does viagra really work viagra online no prescription viagra online cheap natural herbs used as viagra can viagra be used by women buy viagra soft online herbal viagra viagra reviews viagra in the water natural herbs used as viagra cheap viagra overnight
To start earning money with your blog, initially use Google Adsense but gradually as your traffic increases, keep adding more and more money making programs to your site.
hello, thanks for all!!
buy viagra
viagra online
Post a Comment