Topic: Textmate: Rails Bundle Hack to Fix View File Creation

I don't know if anyone will find this useful, but I'll post it anyhow. smile

If you press command-option-down arrow while inside a controller action which does not have an associated view file in TextMate, you'll get a dialog asking you to give a name to create a new view file. I love this feature and I use it a lot, but there is one little annoyance. When creating the view file, it opens it in a new window, not the current project window. Here's a dirty hack that will fix this.

1. Right/Control-click on the Textmate application in the Finder and choose Show Package Contents.
2. Go into Contents/SharedSupport folder and copy over the Rails.bundle to ~/Library/Application Support/TextMate/Bundles directory. This will create a copy of the Rails bundle for you to hack.
3. Choose Show Package Contents on this newly created Rails bundle to see what's inside.
4. In the Rails bundle, open up Support/bin/go_to_alternate_file.rb. You should see something like this near the bottom of that file:

  if choice == :view and !rails_path.exists?
    if filename = TextMate.input("Enter the name of the new view file:", rails_path.basename)
      rails_path = RailsPath.new(File.join(rails_path.dirname, filename))
      rails_path.touch
    else
      TextMate.exit_discard
    end
  end

Add one line to this file (right after rails_path.touch) to refresh the TextMate project drawer before attempting to open the newly created file.

  if choice == :view and !rails_path.exists?
    if filename = TextMate.input("Enter the name of the new view file:", rails_path.basename)
      rails_path = RailsPath.new(File.join(rails_path.dirname, filename))
      rails_path.touch
      TextMate.refresh_project_drawer # <-- add this line!
    else
      TextMate.exit_discard
    end
  end

There we go, save the file and relaunch TextMate. Now the problem mentioned above should be fixed - the newly created file should open up in the project window instead of a new window. Unfortunately this does add a bit of a lag, but it's not bad on my end.

I should mention that any updates made to the Rails bundle inside the TextMate application won't take place since this copied version overrides it. You may want to repeat this hack every once and a while to keep the bundle up to date.

Railscasts - Free Ruby on Rails Screencasts

Re: Textmate: Rails Bundle Hack to Fix View File Creation

Nice hack, have you tried RadRails as yet?  Ive been meaning to but not given it a go.  Although I do dearly love TextMate.

Re: Textmate: Rails Bundle Hack to Fix View File Creation

RadRails is crap compared to textmate for too many reasons.

1) It's slow
2) It's not textmate smile

http://danielfischer.com - Personal Web-Technology-Blog, Los Angeles.

Re: Textmate: Rails Bundle Hack to Fix View File Creation

3) It doesn't have bundles tongue

Thanks for yet another tip Ryan!