This project is archived and is in readonly mode.

#2531 ✓invalid
James Herdman

Fix Rails Templates for Windows

Reported by James Herdman | April 21st, 2009 @ 02:46 AM | in 3.0.2

Rails templates currently don't work with Windows. That thing you think is called "rails" is actually "rails.bat" for Windows. This patch makes things a little better for us stuck in the Enterprise.

Comments and changes to this ticket

  • Jeremy McAnally

    Jeremy McAnally April 21st, 2009 @ 03:35 AM

    Nice! Thanks for fixing that. I didn't have a chance to test in Windows, so this is a very welcome fix. :)

  • Matt Jones

    Matt Jones May 26th, 2009 @ 04:20 PM

    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 for details.

  • Dennis Ushakov

    Dennis Ushakov June 2nd, 2009 @ 02:31 PM

    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

    James Herdman June 2nd, 2009 @ 02:45 PM

    @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 end

    
    Thoughts?
    
  • James Herdman

    James Herdman June 2nd, 2009 @ 02:46 PM

    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 end
    

    Hopefully that worked out better.

  • Dennis Ushakov

    Dennis Ushakov June 2nd, 2009 @ 02:56 PM

    @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

    Roger June 23rd, 2009 @ 04:47 PM

    doesn't accomodate for mingw with RUBY_PLATFORM =~ /mswin|mingw/
    Cheers!

  • Dennis Ushakov

    Dennis Ushakov June 23rd, 2009 @ 09:06 PM

    @Roger: what problems do you see with my patch on mingw?

  • Michael Koziarski

    Michael Koziarski June 26th, 2009 @ 06:14 AM

    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

    James Herdman June 26th, 2009 @ 01:58 PM

    @Michael, perhaps we should talk to Charles Nutter about this issue? JRuby automagically handles the issue at hand.

  • Yehuda Katz (wycats)

    Yehuda Katz (wycats) June 26th, 2009 @ 08:27 PM

    • 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
      end
    

    Seems pretty straight-forward. We could probably grab it for cases where the rubygems library is unavailable.

  • José Valim

    José Valim June 28th, 2009 @ 03:09 PM

    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

    Michael Koziarski June 29th, 2009 @ 01:10 AM

    That sounds like a plan José.

  • James Herdman
  • José Valim

    José Valim June 29th, 2009 @ 08:36 AM

    @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)

    Yehuda Katz (wycats) July 2nd, 2009 @ 07:45 PM

    • 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

    José Valim July 4th, 2009 @ 04:46 PM

    @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

    Repository July 30th, 2009 @ 12:23 AM

    (from [35925a8995e4b3522e4a4e4e52a3a18c9c1cee52]) Ensure that rails templates methods are invoked with the proper extensions [#2531 status:resolved] http://github.com/rails/rails/commit/35925a8995e4b3522e4a4e4e52a3a1...

  • Jeremy Kemper

    Jeremy Kemper October 15th, 2010 @ 11:01 PM

    • Milestone set to 3.0.2
    • Importance changed from “” to “”
  • Jeff Kreeftmeijer

    Jeff Kreeftmeijer November 8th, 2010 @ 08:48 AM

    • Tag cleared.

    Automatic cleanup of spam.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages