Issuing Ruby Commands from Rails?

Hello-

I have an application where I would like to issue Ruby commands from a
Rails application and pipe the resulting stuff from the command line
into a Rails variable.

Does anyone have a good way to do this?

Example:

Call to Ruby P.:

ruby callFunction.rb some_params ( where ‘some_params’ is given from a form in the Rails app)

Results Returned:

result - answer1
result - answer2

Ideally then I could have these results stored in a variable to put in
my view.

Thanks, let me know if this is not clear!

def ruby_command
@result = cd /Users/rails/Desktop/;ls
end

view
<%= @result %>

A start.

I tried this out an when the view is rendered, all I get is what
@result was.

So in the example below, my view displays this:

Result: cd /Users/rails/Desktop/;ls

Pete, check that you’re using backticks (and not single-quotes) in
your code above.

  • BD

At what point does the command get issued? When the view is rendered?

I’m assuming this would work for Windows environment too?

Thanks!

On Dec 15, 9:34 am, Peter De jong [email protected]

Um. I think all the dude wanted to do was to use Ruby code in Rails.

Something like:
<% @result = 1 + 2 %>
<%= @result %>

Am I wrong?

If you want to run your little ruby file there from your Rails app,
stick it
in lib and it will automatically be included if it is a class. If it is
a
module you will have to do include ModuleName to include it.

On Dec 17, 2007 6:54 AM, Brian D. [email protected] wrote:

So in the example below, my view displays this:

A start.

Posted viahttp://www.ruby-forum.com/.


Ryan B.