# Output fleximage image from DB?

**URL:** <https://www.ruby-forum.com/t/output-fleximage-image-from-db/158124>\
**Category:** Rails\
**Created:** [January 19, 2009, 4:08pm UTC](https://www.ruby-forum.com/t/output-fleximage-image-from-db/158124 "2009-01-19T16:08:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [January 19, 2009, 4:08pm UTC](https://www.ruby-forum.com/t/output-fleximage-image-from-db/158124/1 "2009-01-19T16:08:43Z")

</div>

I’m a bit stuck trying to output a DB-stored file in a view with  
FlexImage 2. DB storing is supported but there is no documentation on  
how to get it out of the DB. Could someone point me to a resource  
explaining how to render a DB stored FlexImage in a view?

---

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [January 19, 2009, 4:18pm UTC](https://www.ruby-forum.com/t/output-fleximage-image-from-db/158124/2 "2009-01-19T16:18:09Z")

</div>

Here’s the documentation for a start, I’ve been using FlexImage for a  
while now

[http://wiki.github.com/Squeegy/fleximage](http://wiki.github.com/Squeegy/fleximage)

Since the latest code is for RESTful style controllers/views, etc. You’d  
do something like this in your view that you’re placing your image in.

@image = Image.find(:first)

\<%= image\_tag formatted\_image\_path(@image, :jpg) %\>

This would generate something like this…

![](https://www.ruby-forum.com/images/1.jpg)

which would map to the ImagesController, something like…

class ImagesController \< ApplicationController

def show  
@image = Image.find(params[:id])  
end

end

this would then render the flexi template which might then look like  
this.

app/views/images/show.jpg.flexi:  
@image.operate do |i|  
i.resize ‘200’  
end

I hope this helps or at least the documentation link does.

RobL

> **[Posts](https://www.robl.me/)**
>
> I write thems codes

---

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [January 19, 2009, 4:44pm UTC](https://www.ruby-forum.com/t/output-fleximage-image-from-db/158124/3 "2009-01-19T16:44:01Z")

</div>

Thanks for responding. I think my problem comes from rendering a  
collection through partials. It is not calling the ‘show’ method and  
therefore not triggering the routing call to .jpg. But my best effort  
still doesn’t work:

VIEW  
\<%= image\_tag(url\_for(:controller =\> ‘questions’, :action =\> ‘show’, :id  
=\> question, :format =\> ‘jpg’) %\>

returns:

![](https://www.ruby-forum.com/questions/show/1.jpg)

but just has a broken image link. Its not getting the data.

QUESTIONS\_CONTROLLER:  
def show  
@question = Question.find(params[:id])

```
respond_to do |format|
  format.html # show.html.erb
  format.xml { render :xml => @question }
  format.jpg #for fleximage
end

```

/QUESTIONS/VIEW.SHOW.JPG.FLEXI:  
@question

ROUTES.RB  
map.resources :questions

---

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [January 19, 2009, 8:25pm UTC](https://www.ruby-forum.com/t/output-fleximage-image-from-db/158124/4 "2009-01-19T20:25:40Z")

</div>

Taylor S. wrote:

> Going to the image directly by /questions/show/1.jpg yields the  
> following error:
> 
> NoMethodError in QuestionsController#show
> 
> undefined method `call’ for Fleximage::View:Class

This continues to be my sticking point. The server throws these errors  
silently. More info on the error:

NoMethodError (undefined method `call’ for Fleximage::View:Class):

```
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_view/renderable.rb:21:in 

```

`\_unmemoized\_compiled\_source’

This is on Rails 2.2.2. When installing I also had to change this line  
in plugins/fleximage/init.rb

FROM  
ActionView::Base.register\_template\_handler :flexi, Fleximage::View

TO  
ActionView::Template.register\_template\_handler :flexi, Fleximage::View

So I wonder if there are other issues at work. Anyone on Edge rails  
running fleximage ok? I can get the images to work when I use  
embedded\_image\_tag but have had issues with image corruption really  
blowing up my app. (have to drop the row from DB) Man, you spend more  
time troubleshooting and shoehorning plugins than you do just writing  
the functions from scratch!

---

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [January 19, 2009, 9:07pm UTC](https://www.ruby-forum.com/t/output-fleximage-image-from-db/158124/5 "2009-01-19T21:07:11Z")

</div>

Issue resolved. Somehow I had downloaded an old version of the plugin  
from GitHub. The Dec 12th build solves everything. I love Mondays.

---

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [January 19, 2009, 4:47pm UTC](https://www.ruby-forum.com/t/output-fleximage-image-from-db/158124/6 "2009-01-19T16:47:00Z")

</div>

Going to the image directly by /questions/show/1.jpg yields the  
following error:

NoMethodError in QuestionsController#show

undefined method `call’ for Fleximage::View:Class
