Render Fleximage inline
May 7th, 2008
When you write your plugins the right way, Rails just works in nice ways for you. madrobby (a.k.a. Thomas Fuchs, as made famous by script.aculo.us javascript awesomeness), provided a useful tip in the Fleximage wiki on GitHub.
If you have some quick and small templates for a simple resize operation, you can do a render :inline in order to create a template on the fly for quick and easy rendering of a small template. Try this in your controller:
1 2 3 4 |
def thumb @photo = Photo.find(params[:id]) render :inline => "@photo.operate {|p| p.resize '100x100'}", :type => :flexi end |
I have never used an inline template before, but I can definitely see how that could be handy. Although, to be honest, I feel like this is very much view logic and would like to see this in a view file in all but the absolute simplest cases.
Thanks for the tip Thomas!
May 16th, 2008 at 07:47 PM
Hi,
I’m using this code you suggest and its its very handy. However I’m getiing binary data instead of the image itself. How can I solve this ?
Thanks
Jooel
May 17th, 2008 at 12:05 PM
I haven’t noticed that in my tests running this code. Sounds like rails is not sending the right content type header along with the image data.
Does your route have a format parameter on it? My test route looks like this:
Which I can then activate with:
This will help enforce the right headers are not being sent.
If that is not the issue, I need to know more about your use case to help you trouble shoot it.
June 17th, 2008 at 10:16 PM
Hi Alex, just stumbled over fleximage – looks indeed very handy: But are you using rmagick for all the imaging-stuff?! I didn’t find a clear indication in the docs… After wrestling with the complex, memory-leaking beast that imagemagick is, I’m still loooking for some alternatives for doing basic imaging-operations…
cheers stefan