SitePoint Sponsor |
|
User Tag List
Results 1 to 9 of 9
-
Nov 30, 2006, 04:59 #1
- Join Date
- Oct 2006
- Location
- Kathmandu, Nepal
- Posts
- 4,013
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Execute/Run the Ruby (.rb) files from browser.
Hello ruby users,
I am not new at all for ruby because i have studied for a month about ruby. Actually i need to create a heatmap (the overlay image that shows the click locations in my web page) for my site using ruby on rails which i got reference from http://blog.corunet.com/english/the-definitive-heatmap. And i am successfull to create heatmap in my local machine. Also i tried everything installing (ImageMagick, RMagick, Ruby as well as other needed software) and i am success now to create the images using RMagick/ImageMagick in the server from COMMAND LINE only. When i run the image creating code form command line as ruby something.rb. It reads the data from a text file and writes into a file that shows the click maps of my site. But when i run this same code from browser from a controller class and method, it does not work neither it gives me the error.
And hereby now i want to know how to run or how to call the something.rb file which generates the image successfully from command line (SSH in PUTTY) from my controller class (calling method). How can we execute that .rb file from my ruby code (executing ruby files).
I dont know whether i could make you understood my problem. Please help me. I am spending lots of days for this but i could not do.
Thank you very much help in advance.
Raju Gautam
A New Ruby Programmer
-
Nov 30, 2006, 10:45 #2
- Join Date
- Aug 2005
- Posts
- 986
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You can use ` (backtick) to execute programs:
Code:puts `ls`
-
Nov 30, 2006, 22:38 #3
- Join Date
- Oct 2006
- Location
- Kathmandu, Nepal
- Posts
- 4,013
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Do you mean like this ?
Code:class HeatmapController < ApplicationController layout "standard-layout" def initialize require 'rubygems' require 'RMagick' end def index end def write_click #something to write into file end def WriteImage `ruby /path/to/myfile/toexecute/file.rb` end end
This is not executing the file.rb at all. But when I run this file from command line asCode:ruby file.rb
-
Dec 1, 2006, 06:02 #4
- Join Date
- Aug 2005
- Posts
- 986
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Are you sure that it isn't executing the script? The path may be wrong.
-
Dec 2, 2006, 22:06 #5
- Join Date
- Oct 2006
- Location
- Kathmandu, Nepal
- Posts
- 4,013
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Fenrir2
Code:class HeatmapController < ApplicationController layout "standard-layout" def initialize require 'rubygems' require 'RMagick' end def index end def write_click #something to write into file end def WriteImage `/usr/lib/ruby /path/to/myfile/toexecute/file.rb` end end
Do i need any permissions to execute the files like that?Last edited by Raju Gautam; Dec 2, 2006 at 22:56.
-
Dec 3, 2006, 01:24 #6
- Join Date
- Mar 2004
- Location
- Grand Junction, CO
- Posts
- 292
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You can use "load filename.rb" to load the file in.
I think a much better bet would be to extract the script code into a class that does what you want. Then you can do something like
Code:def write_image ImageGenerator.from_file 'your_text_file' end
-
Dec 3, 2006, 01:53 #7
- Join Date
- Oct 2006
- Location
- Kathmandu, Nepal
- Posts
- 4,013
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
What about the path in ruby? When i load a file
Code:load 'something.rb'
Please can anyone help on this matter too.
With Regards
RajugLast edited by Raju Gautam; Dec 3, 2006 at 03:00.
-
Dec 3, 2006, 03:30 #8
- Join Date
- Mar 2004
- Location
- Grand Junction, CO
- Posts
- 292
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Well, basically, that's just a crappy solution in the first place. As I mentioned, you're way better off encapsulating the behavior you want into a class of its own.
-
Dec 3, 2006, 03:33 #9
- Join Date
- Mar 2004
- Location
- Grand Junction, CO
- Posts
- 292
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by rajug
require File.dirname(__FILE__) + '/some_other_folder/some_other_file'
Bookmarks