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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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"
On Sep 27, 9:35 pm, Max Dev
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> 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
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Sep-28 09:16 UTC
Re: [How to pass argument from a script to rails...]
On 28 Sep 2008, at 02:35, Max Dev <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > 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 youHave 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> > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Sep-28 15:39 UTC
Re: [How to pass argument from a script to rails...]
On Sep 28, 4:20 pm, Max Dev <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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 ``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> > What''s the difference? > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thank you very much Frederick, this has opened my eyes. Then, my mistake was to believe that I need "" for interpolation in ``. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---