# \[How to pass argument from a script to rails...\]

**URL:** <https://www.ruby-forum.com/t/how-to-pass-argument-from-a-script-to-rails/149679>\
**Category:** Rails\
**Created:** [September 28, 2008, 3:35am UTC](https://www.ruby-forum.com/t/how-to-pass-argument-from-a-script-to-rails/149679 "2008-09-28T03:35:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxdunn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maxdunn](https://www.ruby-forum.com/u/maxdunn)\
**Post date:** [September 28, 2008, 3:35am UTC](https://www.ruby-forum.com/t/how-to-pass-argument-from-a-script-to-rails/149679/1 "2008-09-28T03:35:08Z")

</div>

I have a script with which I want to create a rails app.

Then not something like:

$ rails -d mysql name\_app

in terminal, but from the script.

In the script I get the app name, database etc.  
After some operations I would like to create the app from the script,  
but when I try something like

`rails"#{ARGV}"`

where ARGV = name\_app-d mysql

creates the app with a name like name\_app-dmysql.

How can I pass ARGV to successfully create the app?  
Thank you

---

<div class="post-metadata">

**Author:** ![maxdunn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maxdunn](https://www.ruby-forum.com/u/maxdunn)\
**Post date:** [September 28, 2008, 11:17am UTC](https://www.ruby-forum.com/t/how-to-pass-argument-from-a-script-to-rails/149679/2 "2008-09-28T11:17:35Z")

</div>

On 28 Sep 2008, at 02:35, Max D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> After some operations I would like to create the app from the script,  
> but when I try something like
> 
> `rails"#{ARGV}"`
> 
> where ARGV = name\_app-d mysql
> 
> creates the app with a name like name\_app-dmysql.
> 
> How can I pass ARGV to successfully create the app?  
> Thank you

Have you looked at what #{ARGV} evaluates to? The default to\_s on  
arrays just concatenates the elements, whereas you want to have a  
space between them which join will do. On top of that you’ve put "  
round that which will tell the shell ‘all this should be one argument’.

Fred

---

<div class="post-metadata">

**Author:** ![maxdunn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maxdunn](https://www.ruby-forum.com/u/maxdunn)\
**Post date:** [September 28, 2008, 11:29am UTC](https://www.ruby-forum.com/t/how-to-pass-argument-from-a-script-to-rails/149679/3 "2008-09-28T11:29:56Z")

</div>

would ARGV.join(" ") help?

Ruby is using to\_s behind the scenes. Calling to\_s on an array returns  
the values concatenated together in a string

> > [1,2,3].to\_s  
> > =\> “123”

---

<div class="post-metadata">

**Author:** ![maxdunn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maxdunn](https://www.ruby-forum.com/u/maxdunn)\
**Post date:** [September 28, 2008, 5:20pm UTC](https://www.ruby-forum.com/t/how-to-pass-argument-from-a-script-to-rails/149679/4 "2008-09-28T17:20:39Z")

</div>

Thank you for replies.

> Have you looked at what #{ARGV} evaluates to?

> would ARGV.join(" ") help?

Yes, this works well with a call like:

system (or sh) ("‘rails’ #{ARGV.join(’ ')}")

but not with:

`"'rails' #{ARGV.join(' ')}"`

sh: ‘rails’ prova -d mysql: not found

I tried different forms, including with join. My real mistake was that I  
was using the notation ``

What’s the difference?

---

<div class="post-metadata">

**Author:** ![maxdunn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maxdunn](https://www.ruby-forum.com/u/maxdunn)\
**Post date:** [September 28, 2008, 5:40pm UTC](https://www.ruby-forum.com/t/how-to-pass-argument-from-a-script-to-rails/149679/5 "2008-09-28T17:40:21Z")

</div>

On Sep 28, 4:20 pm, Max D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> `"'rails' #{ARGV.join(' ')}"`
> 
> sh: ‘rails’ prova -d mysql: not found
> 
> I tried different forms, including with join. My real mistake was that I  
> was using the notation ``

There’s nothing wrong with using ``, except that you’re quoting rather  
excessively

`rails #{ARGV.join(' ')}`

is fine, as is

system(“rails #{ARGV.join(’ ')}”)

but `"rails ..."` isn’t. `` is already a quoting operator so you don’t  
need the quotes (which makes the shell believe you want to run a  
command called “rails -d mysql some\_app” (ie it will look for  
something whose filename is that whole string) whereas you want to run  
a command called “rails” but passing those arguments.

Fred

---

<div class="post-metadata">

**Author:** ![maxdunn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@maxdunn](https://www.ruby-forum.com/u/maxdunn)\
**Post date:** [September 28, 2008, 5:55pm UTC](https://www.ruby-forum.com/t/how-to-pass-argument-from-a-script-to-rails/149679/6 "2008-09-28T17:55:16Z")

</div>

Thank you very much Frederick,

this has opened my eyes. Then, my mistake was to believe that I need “”  
for interpolation in ``.
