I actually did. I tried various File.expand_path versions too. I even tried moving to the proper directory via Dir.chdir. Any other ideas? I’m just stumped and stymied.
Lemme start out by begging. I really need help with this one. Any
suggestions at all. Now that that's out of the way...
I'm trying to call script/generate from within Rails and having no luck.
I've tried a couple of different ways.
# system "script/generate site_contents X"
which returns false when it fails but I can't get any information
other than the false return.
# `script/generate site_contents X` [in backticks]
this just returns nil from within Rails even though from irb it
returns the STDOUT from the command.
I'm thanking you in advance because you're really gonna save me on this one.
Thank you thank you thank you. Please thank you.
This is the long way to do it just to show you the steps but this should work, at least under Unix/Linux:
cwd = `pwd`
cwd.chomp! # pwd returns a LF at the end
logger.debug("cwd: #{cwd}")
generate = cwd + "/script/generate controller test > #{cwd}/gen_test.out"
logger.debug("generate: #{generate}")
system(generate)
I tried what you suggested, running those two rails_generator requires and got a new error:
couldn’t find HOME environment – expanding `~’
which is, of course a common Windows error. Except that I’m running Unix. Lovely, right? Whoa! I just checked ENV.inspect and got an empty hash! I’m gonna have to look into this. Uh, this is not right, is it kittens?
Okay. I’ve done some snooping and discovered that when I run ENV from the console I get something approximating all my shell variables but when I run it from an apache instance, I get nothing. I can set it [via SetEnv HOME /whatever] in the apache files but it never shows up in the ENV variable! I understand that the shell ENV and the Apache ENV are different but I’m not sure how to correctly set this now.
Help? I mean… Thank you for your future help! Please?
Thankfully, I remembered the whole ENV[“RAILS_ENV”] ||= “production” hack and have used this to set ENV[“HOME”]. Thank you so much to Michael and especially Ben for all your help. I’ve got a new problem now [with permissions on something in the generator process] but this one is solved and I’ll probably be able to hack around and find what’s up with this one.