# Executing a generator on the browser

**URL:** <https://www.ruby-forum.com/t/executing-a-generator-on-the-browser/159916>\
**Category:** Rails\
**Created:** [February 10, 2009, 1:02am UTC](https://www.ruby-forum.com/t/executing-a-generator-on-the-browser/159916 "2009-02-10T01:02:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbtosurf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/59ef9b/32.png) [@bbtosurf](https://www.ruby-forum.com/u/bbtosurf)\
**Post date:** [February 10, 2009, 1:02am UTC](https://www.ruby-forum.com/t/executing-a-generator-on-the-browser/159916/1 "2009-02-10T01:02:30Z")

</div>

Hi

I currently have a generator which creates a directory of files. I  
want clients on my app to be able to execute that generator and save  
those files in their personal folder on the server. The thing is that  
I have always executed this generator via terminal and it always  
creates the series of files on the current path on the terminal where  
I executed the command. How can a user execute this generator on the  
browser and the files be created in his personal folder.

thanx

---

<div class="post-metadata">

**Author:** ![bbtosurf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/59ef9b/32.png) [@bbtosurf](https://www.ruby-forum.com/u/bbtosurf)\
**Post date:** [February 10, 2009, 2:11pm UTC](https://www.ruby-forum.com/t/executing-a-generator-on-the-browser/159916/2 "2009-02-10T14:11:38Z")

</div>

I’m not sure of what you’re asking, but if this ‘generator’ is an  
application residing on the server running your web application, you  
can call it using the ruby command system(‘executable\_name’).

regards,  
rey9999

---

<div class="post-metadata">

**Author:** ![bbtosurf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/59ef9b/32.png) [@bbtosurf](https://www.ruby-forum.com/u/bbtosurf)\
**Post date:** [February 10, 2009, 3:49pm UTC](https://www.ruby-forum.com/t/executing-a-generator-on-the-browser/159916/3 "2009-02-10T15:49:25Z")

</div>

Hello Rey and thanks for your answer. This generator belongs to a gem.  
So the idea is that when a user is browing my website and click on a  
specific button this generator should be executed and directory of  
files is created on his personal folder on the server (this folder is  
created when a user signs up)

Thanks,

Elías

---

<div class="post-metadata">

**Author:** ![bbtosurf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/59ef9b/32.png) [@bbtosurf](https://www.ruby-forum.com/u/bbtosurf)\
**Post date:** [February 10, 2009, 5:59pm UTC](https://www.ruby-forum.com/t/executing-a-generator-on-the-browser/159916/4 "2009-02-10T17:59:19Z")

</div>

My advice stands.  
You’ll need to call the generator using system  
e.g.: system(script/generate blah blah parameters here)  
selecting a target directory could be another story, if this generator  
does not accept a target as a parameter. how about moving the  
generated files after you’ve run the command?

Regards,  
Rey9999

---

<div class="post-metadata">

**Author:** ![bbtosurf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/59ef9b/32.png) [@bbtosurf](https://www.ruby-forum.com/u/bbtosurf)\
**Post date:** [February 10, 2009, 6:12pm UTC](https://www.ruby-forum.com/t/executing-a-generator-on-the-browser/159916/5 "2009-02-10T18:12:51Z")

</div>

Yes it works great, thanks a lot Rey!
