Frank_in_Tennessee
2010-Jan-30 03:44 UTC
run ''script/generate controller'' from inside app
Is it possible to run generator commands from within a running rails
application?
I''m experimenting with creating an application that can create
''views''
on the fly.
In my ''pages_controller.rb'' I have the following code:
# Run Ruby script to create all pages defined in
''website_pages.txt''
load "/railsprojects/#{Website.find(@page.website_id).name}/public/
build_pages.rb"
In my ''build_pages.rb'' I have the following code:
f = File.open("website_pages.txt", "r")
f.each_line do |page|
ruby script/generate controller page
end
file.close
The ''ruby script/generate controller page'' command fails.
Does anyone
know how this line of code can be changed so that it will work?
Thanks,
Frank
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
http://www.gotripod.com/2007/10/07/tip-running-command-line-shell-commands-in-ruby-using-x/
Try this instead:
f.each_line do |page|
%x[script/generate controller #{page}]
end
file.close
;)
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
You can also invoke the generator by hand:
require ''rails/generators''
require ''generators/rails/controller/controller_generator''
Rals::Generators::ControllerGenerator.start %w(page),
{}, :destination_root => "path/to/tmp/dir"
Where :destination_root is the place you want to lay the generated
templates. You could put them in a temp directory and then zip/tar.gz
the directory''s content and send them.
On Jan 30, 12:42 pm, Kristian
<kmand...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> http://www.gotripod.com/2007/10/07/tip-running-command-line-shell-com...
>
> Try this instead:
>
> f.each_line do |page|
> %x[script/generate controller #{page}]
> end
> file.close
>
> ;)
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Marnen Laibow-Koser
2010-Jan-30 14:21 UTC
Re: run ''script/generate controller'' from inside app
Frank_in_Tennessee wrote:> Is it possible to run generator commands from within a running rails > application? > > I''m experimenting with creating an application that can create ''views'' > on the fly.This sounds like a bad idea, but if you really want to try it, then I think that running the generators is the wrong approach. Remember that Ruby can programmatically define classes and methods. That''s what you should be doing in this case.> > In my ''pages_controller.rb'' I have the following code: > > # Run Ruby script to create all pages defined in > ''website_pages.txt'' > load "/railsprojects/#{Website.find(@page.website_id).name}/public/ > build_pages.rb" > > In my ''build_pages.rb'' I have the following code: > > f = File.open("website_pages.txt", "r") > f.each_line do |page| > ruby script/generate controller page > end > file.close >You really shouldn''t be using a separate controller action for each page in this case. Instead, have one controller action that takes the page name as a parameter. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frank_in_Tennessee
2010-Jan-30 17:10 UTC
Re: run ''script/generate controller'' from inside app
I appreciate everyones feedback. I will experiment with all suggestions. Thank you, Frank -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.