I use "Gruff" to draw a graph for my database table
the last step of this function is to create a image in the folder
bar_chart.write("/home/lawyer/Capistrano/current/app/assets/images/graph/lawfirm_#{@lawyer.id}.png")
and in the show page :it will use this image to show in a certain div
-if File.exists?("/home/lawyer/Capistrano/current/app/assets/images/graph/lawfirm_# {@lawyer.id}.png")
= image_tag("graph/lawfirm_#{@lawyer.id}.png")
it works fine in my local host .but in production the image always not shown .
In the console log it shows the error message:
Started GET "/assets/graph/lawfirm_2673.png" for 217.86.186.128 at 2013-05-15 10:19:04 +0200
Served asset /graph/lawfirm_2673.png - 404 Not Found (3ms)
ActionController::RoutingError (No route matches [GET] "/assets/graph/lawfirm_2673.png"):
BUt sometimes it work. it can show the image.
At first the function of draw a graph is in the same controller and same method "index", I hope to draw the graph first then show the image. so I add
before_filter :draw_graph
and move the draw graph function in the method "draw_graph"
but still the same problem
You're writing your image into app/assets; by default, Rails does not serve assets from there in production (see
config.assets.compile
inconfig/environments/production.rb
).Try instead writing your image to
and change your image_tag to
This will write your dynamic images into the
public/system/
folder instead.