Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Fix Rails Templates for Windows

#2531

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.

Reported by James Herdman · April 21st, 2009 @ 02:46 AM

State: invalid
Milestone: 3.0.2
Assigned to: Yehuda Katz (wycats) Yehuda Katz (wycats)
Importance: none

Activity

  1. Jeremy McAnally
    Jeremy McAnally

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

    April 21st, 2009 @ 03:35 AM

  2. Matt Jones
    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.

    May 26th, 2009 @ 04:20 PM

  3. Dennis Ushakov
    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.

    June 2nd, 2009 @ 02:31 PM

  4. James Herdman
    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 end

    
    Thoughts?
    

    June 2nd, 2009 @ 02:45 PM

  5. James Herdman
    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 end
    

    Hopefully that worked out better.

    June 2nd, 2009 @ 02:46 PM

  6. Dennis Ushakov
    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)

    June 2nd, 2009 @ 02:56 PM

  7. Roger
    Roger

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

    June 23rd, 2009 @ 04:47 PM

  8. Dennis Ushakov
    Dennis Ushakov

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

    June 23rd, 2009 @ 09:06 PM

  9. Michael Koziarski
    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? ;)

    June 26th, 2009 @ 06:14 AM

  10. James Herdman
    James Herdman

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

    June 26th, 2009 @ 01:58 PM

  11. Yehuda Katz (wycats)
    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
      end
    

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

    June 26th, 2009 @ 08:27 PM

  12. José Valim
    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?

    June 28th, 2009 @ 03:09 PM

  13. Michael Koziarski
    Michael Koziarski

    That sounds like a plan José.

    June 29th, 2009 @ 01:10 AM

  14. James Herdman
  15. José Valim
    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.

    June 29th, 2009 @ 08:36 AM

  16. Yehuda Katz (wycats)
    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
    

    July 2nd, 2009 @ 07:45 PM

  17. José Valim
    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.

    July 4th, 2009 @ 04:46 PM

  18. Repository
  19. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 3.0.2
    • Importance changed from to

    October 15th, 2010 @ 11:01 PM

  20. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag cleared.

    Automatic cleanup of spam.

    November 8th, 2010 @ 08:48 AM