Last Updated: January 17, 2017
· iamnan

Fix TextMate Code Completion for Rails 4+ Models

You might have noticed that after switching to Rails 4 or 5, a lot of code completions and snippets stopped working. No longer can you type bt hit tab and it expands to belongs_to :object, :class_name => "Object", :foreign_key => "object_id".

Rails generators now create models with the ApplicationRecord base class instead of ActiveRecord::Base. TextMate needed ActiveRecord::Base to recognize the document as a Rails model. Since that's not there anymore, the snippets and shortcuts that depend on that scope aren't fired.

Fixing it take 30 seconds:

  1. Visit Bundle > Edit Bundles in the menu.
  2. Select Ruby on Rails > Language Grammars > Ruby on Rails.
  3. Select the editor window that appears and use Find to search for meta.rails.model. A couple of lines below that, you'll find ActiveRecord::Base. Change that to [ActiveRecord::Base|ApplicationRecord]
  4. Save it, and get back to doing great work.

Screen Shot 2017-01-16 at 3.20.24 PM.png

Say Thanks