Hi,
HELP!
This seems too simple - I MUST be overlooking something…
I can create an rmagick image in my controller and display it fine.
When I create a second image and try to refresh via observe_form, it
shows garbled text…
BTW: RMagick is wonderful.
I am having a difficulty in what seems very elementary in Rails.
-
Create a form that user enters some params (color)
-
Observe the form and create an image (to_blob)
-
Display the image on the same form (near real time). As the user
enter params it builds their image.
What it displays in the div (dynamic image) is…
�PNG IHDR $ �6 pHYsHHF�k>�IDATx���1 �@���C �) ˡKe� �7?�33 R�� � �d$ I @�� �d
$ I @�� �d$ I @�� �d
$ I @�� �d$ I @�� �d
$ I @�� �d$ I @�� �d
$ I @�� �d$��T 4 �W�IEND�B
�
Controller
renders test image for static section - works GREAT.
def test_image
rec_color = “blue”
@color_img = Magick::Image.new(288, 36) {self.background_color
= rec_color }
@color_img.format = ‘png’
@my_blob = @color_img.to_blob
send_data @my_blob, :filename => "mytabs2.png",
:disposition => 'inline',
:type => "image/png"
end
def watch_text # callback for observe form
rec_color = params[:color]
@color_img = Magick::Image.new(288, 36) {self.background_color
= rec_color }
@color_img.format = ‘png’
@my_blob = @color_img.to_blob
send_data @my_blob, :filename => "mytabs.png",
:disposition => 'inline',
:type => "image/png"
end
View
<% form_tag ({:controller => ‘tabs’, :action => ‘create_tabs’} , {:id
=> “entries”}) do -%>
<%= select_tag (:color, options_with_colors(Tab.allowable_colors)) %>
this part renders fine…
<b>static image </b> <br>
<%= image_tag url_for(:controller => "tabs", :action =>
“test_image”, :id => 0) %>
=> (Blue box displays here)
this part shows garbled text…
<b>dynamic image </b> <br>
<div id='results'>
<% if @my_blob %>
<%= image_tag url_for(:controller => "tabs", :action
=> “watch_text”, :id => 0) %>
<% end %>
=> (garbled text here)
�PNG IHDR $ �6 pHYsHHF�k>�IDATx���1 �@���C �) ˡKe� �7?�33 R�� � �d$ I @�� �d
$ I @�� �d$ I @�� �d
$ I @�� �d$ I @�� �d
$ I @�� �d$ I @�� �d
$ I @�� �d$��T 4 �W�IEND�B
�
<%= submit_tag 'Create' %>
<% end %><%= observe_form 'entries', :frequency => 2.0,
:update => :results,
:url => { :action => :watch_text }
%>