I have been doing some searching on the list and have found a potential
solution for displaying images from blob data, however, I am having some
issues getting it work.
My jpeg data is stored in a blob field in the same table as a person’s
information so using one of the available plugins may be difficult.
When I try to load the page the pictures don’t display. I looked at the
logs and it appears that rails is trying to load static content from the
public/images directory. (with the filename being the student’s id and
the file extension “.png”) As a result I get a number of Routing
errors. Is there something wrong with my approach?
I have been doing some searching on the list and have found a potential
solution for displaying images from blob data, however, I am having some
issues getting it work.
My jpeg data is stored in a blob field in the same table as a person’s
information so using one of the available plugins may be difficult.
When I try to load the page the pictures don’t display. I looked at the
logs and it appears that rails is trying to load static content from the
public/images directory. (with the filename being the student’s id and
the file extension “.png”) As a result I get a number of Routing
errors. Is there something wrong with my approach?
Thanks,
Jake
hey, i’m wondering about this line: @image = @student.id_picture
is this @student.id_picture the same as @student.data?
It seems like the image_tag helper is just taking the url that was
generated by url_for and just trying to serve that up as static content
rather than receiving the response from the send_data call.
The logs first show:
DEPRECATION WARNING: You’ve called image_path with a source that doesn’t
include an extension. In Rails 2.0, that will not result in .png
automatically being appended. So you should call
image_path(’/advisor/student_image/65757.png’)
and then the routing errors appear because the static content couldn’t
be found.
It seems like the image_tag helper is just taking the url that was
generated by url_for and just trying to serve that up as static content
rather than receiving the response from the send_data call.
The logs first show:
DEPRECATION WARNING: You’ve called image_path with a source that doesn’t
include an extension. In Rails 2.0, that will not result in .png
automatically being appended. So you should call
image_path(’/advisor/student_image/65757.png’)
and then the routing errors appear because the static content couldn’t
be found.
i have almost the same thing working…now i’m wondering if it’s your
:id; should that be student.id? that’s working for me:
<%= image_tag(url_for(:action => ‘photo’, :id => photo.id), :border =>
0)%>
i have almost the same thing working…now i’m wondering if it’s your
:id; should that be student.id? that’s working for me:
<%= image_tag(url_for(:action => ‘photo’, :id => photo.id), :border =>
0)%>
I have tried a few more things:
Simplifying my student_image method to:
def student_image @student = Student.find_by_id(params[:id])
send_data(@student.id_picture, :content_type => “image/jpeg”)
end
and disambiguating my view (to look more like yours, as well as changing
student to student.id)
i have almost the same thing working…now i’m wondering if it’s your
:id; should that be student.id? that’s working for me:
<%= image_tag(url_for(:action => ‘photo’, :id => photo.id), :border =>
0)%>
I have tried a few more things:
Simplifying my student_image method to:
def student_image @student = Student.find_by_id(params[:id])
send_data(@student.id_picture, :content_type => “image/jpeg”)
end
and disambiguating my view (to look more like yours, as well as changing
student to student.id)
I’m still getting the same results. The action doesn’t seem to be
getting called. Are you running Rails 1.2.1?
no, i’m not – not until i can overcome my daunting obstacles in 1.8!
one thing i forgot which is important. i’m doing these image tags in a
loop: for photo in @photo_collection (which is just a find(:all)).
so photo.id is not @photo.id. i’m sorry, i should have realized that in
my last post.
do you have any ideas for trying to send DOM objects to a controller as
parameters, like say a string array of ids?
no, i’m not – not until i can overcome my daunting obstacles in 1.8!
one thing i forgot which is important. i’m doing these image tags in a
loop: for photo in @photo_collection (which is just a find(:all)).
so photo.id is not @photo.id. i’m sorry, i should have realized that in
my last post.
do you have any ideas for trying to send DOM objects to a controller as
parameters, like say a string array of ids?
That’s exactly what I’m doing. I have a collection of student objects
who each have a photo. This means I have to do two lookups one to get
the student list and one to get their photo while looping through the
students. I’m still confused why I can’t get this to work.
I wish I had more options for dealing with the blob field, however, this
is getting propagated from outside of my rails app.
Has anybody else been able to use this to load blob data into a view (as
an image) with Rails 1.2.1?
no, i’m not – not until i can overcome my daunting obstacles in 1.8!
one thing i forgot which is important. i’m doing these image tags in a
loop: for photo in @photo_collection (which is just a find(:all)).
so photo.id is not @photo.id. i’m sorry, i should have realized that in
my last post.
do you have any ideas for trying to send DOM objects to a controller as
parameters, like say a string array of ids?
That’s exactly what I’m doing. I have a collection of student objects
who each have a photo. This means I have to do two lookups one to get
the student list and one to get their photo while looping through the
students. I’m still confused why I can’t get this to work.
I wish I had more options for dealing with the blob field, however, this
is getting propagated from outside of my rails app.
Has anybody else been able to use this to load blob data into a view (as
an image) with Rails 1.2.1?