This project is archived and is in readonly mode.
Fix Rails Templates for Windows
-
Jeremy McAnally
Nice! Thanks for fixing that. I didn't have a chance to test in Windows, so this is a very welcome fix. :)
-
Matt Jones
Might also want to solicit some input from the JRuby folks, as they have yet another way to run commands (jruby -S rake, for instance). See also discussion on #2215 JRuby platform support for gem tasks. for details.
-
Dennis Ushakov
This is not only problem. Rails template commands (such as plugin) should be run with the same ruby executable that run generator.
So, if I run "c:\ruby-1.8.7\bin\rails.bat myapp" it should use interpeter from c:\ruby-1.8.7\bin.
This problem affects also other platforms. Patch is attached. -
James Herdman
@Dennis Ushakov, good catch, but I'm not sure the best solution is to include Rake as a dependency to get use of FileUtils::RUBY. I think it's fairly safe to consider Ruby in the path of the user. Something like the following might be a little simpler:
@@@ruby def run_ruby_script(command, log_action = true)
run("#{app('ruby')} #{command}", log_action) # where +app+ is defined in my patch endThoughts? -
James Herdman
Wow... I really borked the formatting on that comment.
def run_ruby_script(command, log_action = true) run("#{app('ruby')} #{command}", log_action) # where +app+ is defined in my patch endHopefully that worked out better.
-
Dennis Ushakov
@James Herdman rake isn't really needed, but it's already a dependency for rails if you look at gem spec =) Also, code from rake could be simply copied.
ruby on path isn't a good idea, because someone (for example me) may have couple of ruby interpreters installed and only one of them is in the path. As far as I know, this is common behaviour for mac users (the have built-in ruby and macports) -
Roger
doesn't accomodate for mingw with RUBY_PLATFORM =~ /mswin|mingw/
Cheers! -
Dennis Ushakov
@Roger: what problems do you see with my patch on mingw?
-
Michael Koziarski
While in berlin yehuda and I had a conversation about something along these lines. A cross-platform and 'safe' way to determine the correct ruby command to run.
yehuda, what was it? ;)
-
James Herdman
@Michael, perhaps we should talk to Charles Nutter about this issue? JRuby automagically handles the issue at hand.
-
Yehuda Katz (wycats)
- Assigned user set to Yehuda Katz (wycats)
- State changed from new to verified
- Tag changed from 2.3.2, templates to 2.3.2, 3.0, templates
- Milestone cleared.
Gem.ruby should probably work. It's implemented as:
def self.ruby if @ruby.nil? then @ruby = File.join(ConfigMap[:bindir], ConfigMap[:ruby_install_name]) @ruby << ConfigMap[:EXEEXT] # escape string in case path to ruby executable contain spaces. @ruby.sub!(/.*\s.*/m, '"\&"') end @ruby endSeems pretty straight-forward. We could probably grab it for cases where the rubygems library is unavailable.
-
José Valim
As expected, Yehuda solutions works here on Ruby 1.8, 1.9 and Jruby.
Since I'm working on Rails templates, I can update it and add some tests. Sounds good? -
Michael Koziarski
That sounds like a plan José.
-
James Herdman
How can I help?
-
José Valim
@james, it will still take a couple weeks until my fork gets into master. As soon as it gets, it would be nice if you could test it. :)
@dennis, for *unix users if you have multiple interpreters it must still work because a shebang is added to script files. Although rake might still show the wrong behavior.
-
Yehuda Katz (wycats)
- State changed from verified to invalid
Can you update the patch to use the same thing that Rubygems uses? I wouldn't use Gem.ruby because we want this code to work in the absence of Rubygems as well.
def ruby @ruby ||= begin ruby = File.join(ConfigMap[:bindir], ConfigMap[:ruby_install_name]) ruby << ConfigMap[:EXEEXT] # escape string in case path to ruby executable contain spaces. ruby.sub!(/.*\s.*/m, '"\&"') ruby end end end -
José Valim
@wycats, @nkoz and @james. Just solved this on my Rails fork, the solution includes:
1) The ruby method that Yehuda showed to invoke ruby scripts with the correct interpreter;
2) I've talked with Charles Nutter and he said that the only problem with application generator and templates on jruby is that they had to specify by hand that jruby should be used: rails -r "/usr/bin/env jruby", even if "jruby rails" was being invoked. This is likely to affect Ruby 1.9 as well and was fixed.
3) According to Charles Nutter, invoking rake with jruby is not a problem as long as it's on PATH. So I assumed that the problem is only on windows, where the ".bat" extensions was not added properly. Now the same extension used to invoke ruby is added before invoking rake. So if you are invoking ruby.bat, the template will invoke rake.bat. The same for capify.
@james, if everything goes according to planned, it should be merged next week.
-
Repository
(from [35925a8995e4b3522e4a4e4e52a3a18c9c1cee52]) Ensure that rails templates methods are invoked with the proper extensions [#2531 Fix Rails Templates for Windows status:resolved] http://github.com/rails/rails/commit/35925a8995e4b3522e4a4e4e52a3a1...
