ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Ruby on Rails snippets

by tadast ST2/ST3

Sublime Text snippets for the latest Ruby and Rails versions

Labels snippets

Details

  • 2017.04.17.15.08.29
  • github.​com
  • github.​com
  • 6 months ago
  • 1 hour ago
  • 5 years ago

Installs

  • Total 41K
  • Win 10K
  • OS X 18K
  • Linux 13K
Oct 20 Oct 19 Oct 18 Oct 17 Oct 16 Oct 15 Oct 14 Oct 13 Oct 12 Oct 11 Oct 10 Oct 9 Oct 8 Oct 7 Oct 6 Oct 5 Oct 4 Oct 3 Oct 2 Oct 1 Sep 30 Sep 29 Sep 28 Sep 27 Sep 26 Sep 25 Sep 24 Sep 23 Sep 22 Sep 21 Sep 20 Sep 19 Sep 18 Sep 17 Sep 16 Sep 15 Sep 14 Sep 13 Sep 12 Sep 11 Sep 10 Sep 9 Sep 8 Sep 7 Sep 6 Sep 5
Windows 3 4 4 1 3 4 4 4 4 3 2 5 4 2 2 4 7 4 4 2 8 2 4 6 6 11 1 1 8 5 6 11 9 5 3 5 10 6 6 8 3 3 3 6 4 5
OS X 8 8 7 6 8 2 4 11 6 7 13 3 5 5 9 8 13 7 3 10 5 12 4 5 9 10 8 1 10 18 16 16 24 6 7 9 15 18 7 4 3 1 8 8 8 4
Linux 5 7 7 3 12 2 4 12 6 7 4 6 4 6 4 2 8 6 8 8 4 3 6 4 7 2 12 4 7 6 5 9 12 4 6 7 10 7 5 1 8 3 5 10 7 3

Readme

Source
raw.​githubusercontent.​com

Sublime Text Rails snippets

:warning: I'll be porting these changes to the official Sublime Text Rails snippets. Here's how you can help

This repo provides up-to-date Ruby and Rails snippets for Sublime Text: it's designed to be used with Ruby >= 2.0 and Rails >= 3. All the snippets can be found in this cheatsheet generated by Snipcheat.

class

ActiveRecord

migrations

Installation

If you're using Sublime Text 2, please refer to older installation instructions.

From Package Control

The easiest way to install the snippets is via package control.

However this method has a little downside: it adds new snippets but does not remove the old ones. This means that for some snippet triggers e.g. vp (validates presence) you'll see a drop-down with two options, not one.

Look for “Ruby on Rails snippets” in Package Control. Here's how to install packages

From Git

This method replaces the default outdated snippets, but you have to keep it up to date manually by running git pull every now and again.

To install via git:

  • First, cd into the ST3 Packages directory
# Mac:cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages
➜ # Linux:cd ~/.config/sublime-text-3/Packages/
  • Then clone this repo into the folder
➜ ls | grep Rails
➜ # if there is a `Rails` dir, back it up e.g. archive it and remove the original.
➜ git clone https://github.com/tadast/sublime-rails-snippets.git Rails

It is important to clone it into a folder called Rails. Some Sublime plugins have hard-coded dependencies pointing to that path. See troubleshooting.

Troubleshooting

Syntax highlighting doesn't work

You might need to tell Sublime text to use the Ruby on Rails syntax provided by Ruby on Rails Snippets. With an .rb file open and focused navigate to View -> Syntax -> Open all with current extension as... -> Ruby on Rails Snippets -> Ruby on Rails

Sublime picks Ruby (not Rails) syntax

You might need to tell Sublime to prefer Rails over Ruby by navigating to View -> Syntax -> Open all with current extension as... and picking Rails of Ruby on Rails snippets

Can't find *.tmLanguage

If Sublime complains it can't find Ruby on Rails.tmLanguage, chances are you are using this hack.

You'll need to change the path where it looks for that file. Here's the forked version which works with this plug-in.

You may also need to change Packages/(DetectSyntax|User)/DetectSyntax.sublime-settings to replace/include this rule

{
  "name": "Ruby on Rails snippets/Ruby Haml",
  "rules": [
    {"file_name": ".*\\.haml$"}
  ]
},
{
  "name": "Ruby on Rails snippets/Ruby on Rails",
  "rules": [
    {"function": {"name": "is_rails_file"}}
  ]
}

Ruby on Rails snippets is a default installation directory for Package Control. If you installed in a different directory, change the path accordingly

How to contribute

  1. Fork it
  2. Create your feature branch for each group of snippet changes that could be merged individually (git checkout -b my-new-snippet)
  3. Commit your changes (git commit -am 'Add some snippet [tab_trigger]')
  4. Commit messages should start with a verb in present simple tense and have all affected tab triggers in square brackets e.g. “Add a snippets for partial rendering [rpc, rpo]”
  5. Push to the branch (git push origin my-new-snippet)
  6. Create new Pull Request