Controller
class CreationController < ApplicationController
flex_image :action => ‘show’,:class => LibResource # I don’t get this
line and docs are lacking
That is a macro which makes your controller render image data instead of
HTML. When the action “show” is called, and there is an :id in your
params, it will render the requested image. The :action portion of that
should name an action that is dedicated to rendering image data. If
your controller already has a show action in it for showing
LibResource’s then you need to declare a different method, such as
“show_image” or perhaps just “image”.
Although the recommended current usage is to use flexi views:
#controller
def show_image
@image = LibResource.find(params[:id])
end
#app/views/some_controller_name/show_image.flexi
@image.resize! :size => “123x456”
Just note you need rails 1.2 or newer for flexi views. I really need to
spend some time updating the docs.
Display View
<%= image_tag( url_for(:controller => ‘creation’, :action =>
‘show’, :id => @mod)) %> #heres that show method again?
As you found out, image_tag will append .png to the url automatically if
the url has no extension. This doesn’t work. I recommend to define a
custom route with a .jpg extension.
#Rails >= 1.2
map.image ‘:controller/:action/:id.jpg’
#Rails < 1.2
map.image ‘:controller/:action/:id/image.jpg’
Now:
<%= image_tag image_url(:id => @mod) %>
Should return:
You should be able to go to your action, with an id, and see an image.
SO point your browser to /lib_resources/image/123.jpg and you should get
an image in your browser.
Model
…
image MEDIUMBLOB
by default the binary column should be named “data”. If you want it to
be named differently, use this snippet in your class definition:
class LibResource < FlexImage::Model
binary_column :image
end
I want to be able to upload an image file to the LibResource Model and
store it in the DB and then finish creating other things
Shouldn’t be a problem, although ActiveRecord won’t let you save a
record unless it passes validation. So as long as your model can
validate with only the image saved in it this wont be a problem.
Otherwise you may have to change your approach to upload the file either
during or after the rest of the model’s data is populated.
I then want to be able to show a page with the LibResource Model
data(including the image) and other Model’s data
As long as the image action is different from the show action, this
should be as easy as the image_tag I posted above.
Right now, instead of the image being displayed, just the string of
the id is displayed
This is most likely firefox showing the alt tag of an image that it
couldn’t display. If you point the src of the image to the url that is
dedicated to rendering images it should render properly.
This just seems too complicated. I got file_column working fairly
easily but then had other issues with it. I wish the FlexImage Docs
were better.
Sorry, but I am a better programmer than I am documentation writer. I
also seem to be having a problem keeping that docs up to date. There is
no excuse on my part for the latter. If any FlexImage fans want to help
make the docs rock my socks I’m all for it. Until then I will limp
along to explain things as best I can.
Good luck
Alex
PS: I get RSS notification of every comment on my blog you need further
help. I don’t always see the messages here.