Rails File Switcher is a plugin for Sublime Text 2 that allows you to switch between Models, Controllers and Views. And how!
No popups, just immediately switches to the related file.
- Opens the related model.
- If you put the caret inside a model's name (like Po│st) and run the command, it will open the model from any place in the application. This works for models, services and mailers (examples:
Post
,PostService
,PostMailer
).
- Opens the related controller from a model and rspec model & controller specs.
- Opens the related controller from a view. Centers the screen at the action definition. If Vintage is enabled, it also moves the caret to the action definition.
- Opens the related view from a controller. You need to put the caret inside the controller action for it to work.
- Opens the related rspec model spec.
- If you put the caret inside a model's name (like Po│st) and run the command, it will open the model spec from any place in the application.
- Opens the related rspec controller spec from a model and rspec model.
Here are the default bindings. You can change them in Preferences > Key Bindings - User
{ "keys": ["super+1"], "command": "open_related_rails_model" },
{ "keys": ["super+2"], "command": "open_related_rails_controller" },
{ "keys": ["super+3"], "command": "open_related_rails_view" },
{ "keys": ["super+4"], "command": "open_related_rspec_model" },
{ "keys": ["super+5"], "command": "open_related_rspec_controller" },
How is it different from Rails Related Files and other similar plugins?
Rails Related Files
shows you a list of related files which you can choose from.
Rails File Switcher
switches between MVC files instantly. If you are in your User model and you press ⌘+2 (if that's your binding), you will instantly see UsersController.
Pull requests are appreciated. If something isn't working, you can fix and send a pull request or simply create an issue to let me know of the bugs.
- Add support for
services
andmailers
.
- Add support for singularly-named controllers.
- Add support for jumping from a namespaced controller to a non-namespaced model.
- Add support for RSpec models and controllers.
- Show file creation popup for all types when the file doesn't exist, not only for views.
- Add support for ST3, use branch
python3
(by @dsnipe)
- Allow creating views when switching to a non-existent view.
- Include key bindings by default (by @deiga).
- Add support for namespaces.
- When switching from a view to the controller the screen is centered at the action definition. If Vintage is enabled, it also moves the caret to the action definition.
- Allow switching to model by putting the caret (and running
open_related_rails_model
) inside its name anywhere in the application.
- Make it work when there are multiple apps opened in the side bar (previously would look for files only in the first app). Thanks to @ccodre for pointing out.
- Initial release
The plugin is released under the MIT License