开发者

How to use scruffy with rails

I'm pretty new to ruby on rails and i'm trying to embed some graphs into my application. I chose to use scruffy and I installed the scruffy gem. But now I don't really know how to actually create the graphs. Where do I have to put the code (inside the controller or the view)? Do I call the .render m开发者_JAVA技巧ethod inside the controller or the view? If I call the .render method inside the controller how do I get the graph to show up in my view? And for starters I would just like to render svg images since I don't want to install imageMagick just yet.

Any help would be greatly appreciated! Thanks


What exactly are you trying to do with those graphs?

As i understand, the scruffy gem is ruby library that isn't specifically made for Rails. You should use it like normal ruby script, e.g. create the graph from some data and save it to file. If you do this in Rails application, this code should be placed in one of your models and you should somehow store the url of created image in the model, so you can later easily access it from views. Image creation process is likely to be time consuming, so consider to use some kind of background job for it (e.g. delayed_job).

After the graph was created you can display it in your views in a usual way:

<%= image_tag path_to_graph %>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜