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?
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.
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.