RubyOnRails

Last edit

Summary: Added note for projectile-rails

Added:

> == projectile-rails ==
> If you use [[Projectile]], you might feel at home with [https://github.com/asok/projectile-rails projectile-rails], available on MELPA.


Editing the usual .rb ruby files in rails is no big deal, just use the usual RubyMode. But what about all those .rhtml or .html.erb files?

For those you probably want to use MuMaMo-Mode to combine HtmlMode with RubyMode (most stable), or just use nXhtml (includes MuMaMo and is more feature rich, but slightly less stable) which can handle this combination automatically. For more information and instructions see Rhtml-Setup (while these instructions are part of the Rinari documentation the techniques can be used independent of Rinari).

emacs-rails

Please checkout the most recent version of this mode here. http://github.com/dima-exe/emacs-rails-reloaded/tree/master. It has been improved a lot since this wiki has been last edited. (June 2009)

minor mode for editing RubyOnRails code

Features(svn version):

See more features in http://dima-exe.ru/rails-on-emacs

There are a bunch of forks of emacs-rails on github. Starting at http://github.com/tomtt/emacs-rails/tree/master (see “Network” for other forks). I’m currently using and committing to http://github.com/remvee/emacs-rails/tree/masterJoostDiepenmaat

emacs-rails relies on snippet.el and find-recursive.txt (which is actually an elisp source file :P) – JonathanSimms

Emacs-rails screencast (1.8Mb) shows emacs-rails.el mode in action (autocompletion, navigation etc). It also shows ECB - Emacs Code Browser. Flash required.

Rinari

Rinari is an Emacs Minor Mode for Rails development. Emphasis is placed on TDD, ease of navigation, leverage of Emacs compilation buffers, compliance with Emacs conventions, and playing nice with other tools. See the online Documentation.

Find the latest version of Rinari at github http://github.com/eschulte/rinari/tree/master

(Rinari replaces (and deprecates) arorem.)

Rinari defines some useful functions for navigating quickly between files in a Rails project, unfortunately the default keybindings are a little verbose. I’ve added the following to my .emacs file. The list of bindings was ripped from ‘C-h b’ while in rinari minor mode. [There may well be a better way of doing this, I’m an Emacs newbie….]

  ; When Rinari mode is loaded, add extra bindings to its key map enabling the
  ; use of M-R and M-r as its prefixes. The easier to type M-r is used for the
  ; frequently used `find' functions and M-R is used for the more infrequently
  ; used rake/script/web-server commands. M-r is normally bound to
  ; `move-to-window-line-top-bottom', which I can do without, and M-R is
  ; normally unbound. Examples of the changes below; it should be obvious how to
  ; pick your own prefixes if you don't like mine.
  ;
  ; Function                  Default Binding    New Binding
  ; ========                  ===============    ===========
  ; rinari-find-controller    C-c ; f c          M-r c
  ; rinari-web-server         C-c ; w            M-R w
  (add-hook 'rinari-minor-mode-hook (lambda ()
	(define-prefix-command 'pd-rinari-map1)
	(define-prefix-command 'pd-rinari-map2)
	(local-set-key (kbd "M-R") 'pd-rinari-map1)
	(local-set-key (kbd "M-r") 'pd-rinari-map2)

	(define-key pd-rinari-map1 "'" 'rinari-find-by-context)
	(define-key pd-rinari-map1 ";" 'rinari-find-by-context)
	(define-key pd-rinari-map1 "c" 'rinari-console)
	(define-key pd-rinari-map1 "d" 'rinari-cap)
	(define-key pd-rinari-map1 "e" 'rinari-insert-erb-skeleton)
	(define-key pd-rinari-map1 "g" 'rinari-rgrep)
	(define-key pd-rinari-map1 "p" 'rinari-goto-partial)
	(define-key pd-rinari-map1 "q" 'rinari-sql)
	(define-key pd-rinari-map1 "r" 'rinari-rake)
	(define-key pd-rinari-map1 "s" 'rinari-script)
	(define-key pd-rinari-map1 "t" 'rinari-test)
	(define-key pd-rinari-map1 "w" 'rinari-web-server)
	(define-key pd-rinari-map1 "x" 'rinari-extract-partial)

	(define-key pd-rinari-map2 ";" 'rinari-find-by-context)
	(define-key pd-rinari-map2 "C" 'rinari-find-cells)
	(define-key pd-rinari-map2 "F" 'rinari-find-features)
	(define-key pd-rinari-map2 "M" 'rinari-find-mailer)
	(define-key pd-rinari-map2 "S" 'rinari-find-steps)
	(define-key pd-rinari-map2 "Y" 'rinari-find-sass)
	(define-key pd-rinari-map2 "a" 'rinari-find-application)
	(define-key pd-rinari-map2 "c" 'rinari-find-controller)
	(define-key pd-rinari-map2 "e" 'rinari-find-environment)
	(define-key pd-rinari-map2 "f" 'rinari-find-file-in-project)
	(define-key pd-rinari-map2 "h" 'rinari-find-helper)
	(define-key pd-rinari-map2 "i" 'rinari-find-migration)
	(define-key pd-rinari-map2 "j" 'rinari-find-javascript)
	(define-key pd-rinari-map2 "l" 'rinari-find-lib)
	(define-key pd-rinari-map2 "m" 'rinari-find-model)
	(define-key pd-rinari-map2 "n" 'rinari-find-configuration)
	(define-key pd-rinari-map2 "o" 'rinari-find-log)
	(define-key pd-rinari-map2 "p" 'rinari-find-public)
	(define-key pd-rinari-map2 "r" 'rinari-find-rspec)
	(define-key pd-rinari-map2 "s" 'rinari-find-script)
	(define-key pd-rinari-map2 "t" 'rinari-find-test)
	(define-key pd-rinari-map2 "u" 'rinari-find-plugin)
	(define-key pd-rinari-map2 "v" 'rinari-find-view)
	(define-key pd-rinari-map2 "w" 'rinari-find-worker)
	(define-key pd-rinari-map2 "x" 'rinari-find-fixture)
	(define-key pd-rinari-map2 "y" 'rinari-find-stylesheet)
	(define-key pd-rinari-map2 "z" 'rinari-find-rspec-fixture)
	))

Rails and ri

When you install gems such as Rails, there is no ri documentation generated for it by default. You can do this manually by changing to your gems directory and running “rdoc -Y”, but it takes a very long time to do. Once the ri is generated, use Ri for Emacs to access it.

YARI seems to work better for the latest version of RDoc (2.5.11).

Populating FileNameCache

FileNameCache is a tool that helps with find-file to easily complete filenames regardless of their directory location. Here’s a little defun I wrote to simplify loading a Rails project into FileNameCache:

(require 'filecache)
(defun rails-add-proj-to-file-cache (dir)
  "Adds all the ruby and rhtml files recursively in the current directory to the file-cache"
  (interactive "DAdd directory: ")
    (file-cache-clear-cache)
    (file-cache-add-directory-recursively dir (regexp-opt (list ".rb" ".rhtml" ".xml" ".js" ".yml")))
    (file-cache-delete-file-regexp "\\.svn"))

This can be a slow process, but hopefully having a nicely populated file cache will pay off.

Pastie Support For emacs

Many in the Ruby community use Pastie for sharing code snippets. Emacs integration can be found here: pastie.el or here Lisp:pastie.el

Rails2/Rails3 TDD: espectator + enotify

spectator-emacs, together with enotify and the enotify-spectator-emacs plugin, provide a continuous testing solution for emacs, without the annoying growl-like popups. The notifications are delivered via the emacs modeline.

See Enotify and checkout the spectator-emacs gem. You can also grab spectator-emacs from its git repository. It provides notifications on the modeline and optional alert.el alerts.

If used together with the rspec_org_formatter gem, it provides org formatted rspec output directly in an emacs buffer - just click the notification “icon” in the modeline ☺

The rspec_org_formatter can be grabbed from github as well.

See the README of these packages for more info on how to set them up, or send me a mail for further help (my address can be found on my personal page - AlessandroPiras).

Haml Support for emacs

See HamlMode.

web-mode.el

web-mode.el , a major mode for editing html templates, handles erb files. The mode is available on http://web-mode.org

== Tab-Key in Terminal-Mode

When using the emacs-rails plugin with snippets (tab-expansion), it works nicely in the normal GUI, but in terminal mode the tab-key triggers the indentation but snippets don’t work. Does anyone have any tips for how to fix this? Thanks! Running Emacs-snapshot 23.0.6 on Ubuntu Gutsy Gibbon — Roman

projectile-rails

If you use Projectile, you might feel at home with projectile-rails, available on MELPA.