Projectile Rails is a minor mode for working with the Rails project in GNU Emacs. Internally it based on Projectile.
It means that you can use Projectile's commands for greping (or acking) files, run tests, switch between projects, etc.
With Projectile Rails you can:
- navigate through rails resources (controllers, views, helpers and so on)
- jump to ruby classes and template files
- run
rake
- run
rails console
- run
rails generate
- open log files with
auto-revert-mode
on - see rails keywords highlighted
Once you have setup Melpa you can use package-install
command to install Projectile Rails. The package name is projectile-rails
.
To make it start alongside projectile-mode
:
(add-hook 'projectile-mode-hook 'projectile-rails-on)
That will start it only if the current project is a Rails project.
Probably you should read Projectile's README on setting up the completion system, caching and indexing files. Although the default settings are quite sensible and you should be ready to go without much tweaking.
The mode's buffers will have the Rails keywords higlighted. To turn it off:
(setq projectile-rails-add-keywords nil)
If you are using yasnippet and you open a new file it will be filled with a skeleton class. To turn it off:
(setq projectile-rails-expand-snippet nil)
Command | Keybinding | Description |
---|---|---|
projectile-rails-find-model | C-c r m | Find a model using projectile-completion-system . |
projectile-rails-find-current-model | C-c r M, C-c r g m | Go to a model connected with the current resource. |
projectile-rails-find-controller | C-c r c | Find a controller using projectile-completion-system . |
projectile-rails-find-current-controller | C-c r C, C-c r g c | Go to a controller connected with the current resource. |
projectile-rails-find-view | C-c r v | Find a template or partial using projectile-completion-system . |
projectile-rails-find-current-view | C-c r V, C-c r g v | Go to a view connected with the current resource. |
projectile-rails-find-helper | C-c r h | Find a helper using projectile-completion-system . |
projectile-rails-find-current-helper | C-c r H, C-c r g h | Go to a helper connected with the current resource. |
projectile-rails-find-lib | C-c r l | Find a lib using projectile-completion-system . |
projectile-rails-find-spec | C-c r s | Find a spec using projectile-completion-system . |
projectile-rails-find-current-spec | C-c r S, C-c r g s | Go to a spec connected with the current resource. |
projectile-rails-find-migration | C-c r i | Find a migration using projectile-completion-system . |
projectile-rails-find-javascript | C-c r j | Find a javascript using projectile-completion-system . |
projectile-rails-find-current-migration | C-c r I, C-c r g i | Go to a migration connected with the current resource. |
projectile-rails-find-log | C-c r o | Find a log file and enable auto-revert-tail-mode in its buffer. |
projectile-rails-console | C-c r r | Run rails console command in inf-ruby buffer. |
projectile-rails-rake | C-c r e | Select a rake task to run using projectile-completion-system . |
projectile-rails-generate | C-c r t | Run rails generate command. |
projectile-rails-goto-file-at-point | C-c r RET, C-c r g f | Go to a file at point. Depending on the context that might be a constant, template or partial, or a gem. |
projectile-rails-goto-gemfile | C-c r g g | Go to Gemfile file. |
projectile-rails-goto-routes | C-c r g r | Go to config/routes.rb file. |
projectile-rails-goto-schema | C-c r g h | Go to db/schema.rb file. |
projectile-rails-goto-spec-helper | C-c r g p | Go to spec/spec_helper.rb file. |
You might want to create your own keybinding for your favorite commands. For example:
(define-key projectile-rails-mode-map (kbd "s-m") 'projectile-rails-find-model)
(define-key projectile-rails-mode-map (kbd "s-c") 'projectile-rails-find-controller)
(define-key projectile-rails-mode-map (kbd "s-v") 'projectile-rails-find-view)
(define-key projectile-rails-mode-map (kbd "s-RET") 'projectile-rails-goto-file-at-point)
(define-key projectile-rails-mode-map (kbd "C-c g") projectile-rails-mode-goto-map)
Consider installing other Emacs packages that can help you working specifically with Rails projects.
Extension | Alternatives |
---|---|
erb | web-mode, mmm-mode, rhtml-mode |
haml | haml-mode |
slim | emacs-slim |
yaml | yaml-mode |
Some of the Projectile Rails functions run rake
or rails
executables. If you are using a ruby version manager you might need to configure your Emacs to play nicely with it.
OS X users might want to look at exec-path-from-shell.
- bundler.el to interact with Bundler.
- rspec-mode to run and edit spec files.
- feature-mode to edit feature files.
- robe to view gems documentation and jump to methods and classes definitions.
- magit to interact with git.
Install cask if you haven't already, then:
$ cd /path/to/projectile-rails
$ cask
Run all tests with:
$ make test
For all of them to pass you will need the bundle
executable in your path.