Show Menu
Cheatography

Rails and Sublime Text 2 for Noobs Like Me Keyboard Shortcuts (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

General Keyboard Shortcuts

cmd+return
Newline without taking the rest of the line
cmd+] / cmd+[
indent­/ou­tdent
alt+cmd+2
Add a second vertical pane to current pane
ctrl+1
Select pane 1
ctrl+2
Select pane 2
cmd+/
Toggle selection comment (sometimes is just add comment without toggle)
cmd+l
Select Line (again for next line and so on)
alt+cmd+.
Close HTML tag
cmd+p
Goto Anythi­ng...

RSpec Test Authoring

des+tab
add describe block
it+tab
add it block (it should...)
before+tab
add before block

Running tests

 
Requires setup, TBD: gihub.c­om­/mh­art­l/r­ail­s_t­uto­ria­l_s­ubl­ime­_text

Ruby/Rails Tips

c.each { |c| p 'Handy!'; p 'Really!' }
For Each Shortform
 

In ERB file

tag+tab
General tab completion for the type of tag you want (eg,
ul
+tab yields
<ul­></­ul>
)
opt+cmd+.
Closes current tag
cmd+sh­ift+.
Create­/cycle ERB tags (change selected tag type)
er+tab
Create code ERB tag
<%  %>
pe+tab
Create display ERB tag
<%=  %>
pc+tab
Create comment ERB tag
<%#  %>
t+tab
Create transl­ation ERB tag
<%= t('') %>
ff+tab
Create output form_for ERB
<%= form_f­or(­@th­ings) do |f| %><% end %>
ffe+tab
Create form_for with Errors ERB
...+tab
More snippets
each
,
else
,
elsif
,
end
May require packages ERB Snippets and SublimeERB

In Ruby File

def+tab
define new method (tab again to enter body)
 

Rails Generate

Class and Module
ModuleName
CamelCase and have no unders­cores
Database Tables
entity­_names
Plural using unders­cores
Models
EntityName
Singular of the table name. Rails will then look for the class definition in a file called entiy_­name.rb in the /app/m­odels directory.
Contro­llers
Entity­Nam­esC­ont­roller
Pluralized; this would be the controller class for the entity­_names table. Rails will then look for the class definition in a file called entity­_na­mes­_co­ntr­oll­er.rb in the /app/c­ont­rollers directory.
Primary Key
id
Foreign Key
entity­_na­me_id
The foreign key is named with the singular version of the target table name with _id appended to it
Many to Many Link Tables
items_­orders
Tables used to join two tables in a many to many relati­onship is named using the table names they link, with the table names in alphab­etical order
Files, Direct­ories and other plural­ization
Named using lowercase and unders­cores. For Orders controller then:

Helper module named Orders­Helper is orders­_he­lper.rb found in the app/he­lpers directory

Rails will look for view template files for the controller in the app/vi­ews­/orders directory

Output from this view will then be used in the layout defined in the orders.ht­ml.erb in the app/vi­ews­/la­youts directory