textmate ruby/rails cheat sheet
DESCRIPTION
keyboard shortcuts/reference card; Additionally, there are accompanying cheat sheets for general TextMate usage and Django for TextMate from me.TRANSCRIPT
RUBY COMMANDS ⌃⌥⇧R
Ruby rcode completion ⌥⎋
Run rake task ⌃⇧R
Run current UnitTest ⌘⇧R
Open require ⌘⇧D
Insert missing requires ⌃#
Execute Line/Selection ⌃⇧E
SQL COMMANDS ⌃⌥⇧S
Database browser ⌥⌘⇧D
Execute line/selection ⌃⇧Q
RUBY CODE
Toggle string/symbol ⌃:
Toggle do .. end / { .. } ⌃{
Insert/toggle ERb (select.) ⌃>
Add ! to method in line ⌃!
Begin .. rescue .. end ⌃⇧W
Hash pointer ʻ => ʻ ⌃L
Embed select. code #{..} #
RUBY SNIPPETS
require “..” req⇥
File (foreach, read, open) File⇥
Option parser block optp⇥
Add option opt⇥
UnitTest, TestCase block tc⇥
def test_name .. end deft⇥
assert test, message as⇥
assert_(([a-z])[a-z]+_?)+ as[a-z]+⇥
New rdoc block =b⇥
[case, elsif, if, unless,[...⇥
when, while] block[...⇥
If .. else .. end ife⇥
New module mod⇥
:key => “value”[,] :⇥
:yieds: arguments y⇥
{ |variables| .. } {⇥
do |variables| .. end do⇥
RUBY CLASSES
New Ruby (Rails) class cla⇥
def self.name .. end defs⇥
alias_method :new, :old am⇥
attr_[read,write,access] .. [r,w,rw]⇥
RUBY FUNCTIONAL
Array.new(..) { |i| .. } Array⇥
Hash.new { |h,k| h[k] = .. } Hash⇥
[all,any]? { |e| .. } [all,any]⇥
each { |e| .. } ea⇥
each_(([a-z])[a-z]+_?)+ ea[a-z]+⇥
reverse_each { |e| .. } reve⇥
inject(init) { |mem, var| .. } inj⇥
lambda { |args| .. } lam⇥
map { |e| .. } map⇥
map_with_index { |e, i| .. } mapwi⇥
zip(enums) { |row| .. } zip⇥
TextMate Ruby/Rails/SQL/YAML Cheat Sheet
TextMate Ruby/Rails/SQL/YAML Cheat Sheet
RAILS COMMANDS ⌃⌥⇧R
Show classʼ DB schema ⌃⌘⇧S
Goto alternate file ⌥⌘↓
Goto specific file ⌥⌘⇧↓
Goto file on current line ⌥⌘↑
Generators, migrations,⌃| (pipe)
fixtures, schema cmds⌃| (pipe)
Generate a migration ⌃⇧M
Test ... (rake test tasks) ⌃\
YAML COMMANDS ⌃⌥⇧Y
Autocomplete FK fixture⌥[⇧]⎋
reference [habtm]⌥[⇧]⎋
key: value snippet ⌃:
Convert to Ruby ⌃⇧H
Syntax cheat sheet ⌃H
Add list item ⌅
Sort keys alphabetically F5
RAILS SNIPPETS
“session[:user]” snippet ⌃J
“params[:id]” snippet ⌃P
flash[:notice] = “msg” flash⇥
[c,m]attr_accessor :name [c,m]rw⇥
redirect_to ([something]+) re[s]+⇥
render ([something]+) r[s]+⇥
verify [redirect, render] verify⇥
assert(v = assigns(:v)) asg⇥
assert_response asre⇥
assert_rjs asrj⇥
associations: use initials ...⇥
has_many :dependent hmd⇥
has_many :through hmt⇥
validates_(([a-z])[a-z]+_?)+v[a-z]+⇥
(w/o “_of”, add “if” for :if)v[a-z]+⇥
before_[a-z][a-z]+ bef[cdus]⇥
after_[a-z][a-z]+ aft[cdus]⇥
find([:all,:first,id]) fin[a,f,i]⇥
logger.level logl⇥
returning do |var| .. end returning⇥
xhr [get,post,put,delete] x[…]⇥
SCOPE REFERENCE
CONTROLLER
respond to (sel. text) ⌘⇧H
def create method block defcreate⇥
CUCUMBER ⌃⌥⇧C
Feature fea⇥
Scenario, Outline sc[e,o]⇥
[Given, When, Then] step [giv,whe,the]⇥
Autocomplete step ⌥⎋
Create all undef. steps ⌃⌥⌘⇧↓
Goto current step ⌃⌥⇧↓
Run feature ⌘R
Run single scenario ⌘⇧R
Align table cells ⌥⌘\
TextMate Ruby/Rails/SQL/YAML Cheat Sheet
TextMate Ruby/Rails/SQL/YAML Cheat Sheet
MIGRATIONS
Manipulate table mtab⇥[⇥]
Manipulate colum[s] mcol⇥[⇥]
Create columns mccc⇥
Rename column[s] mncc⇥
Manipulate index mind⇥
t.column (snippet name) t.⇥
RJS
page.hide hide⇥
page.insert_html ins⇥
page.replace rep⇥
page.replace_html reph⇥
page.show show⇥
page.toggle tog⇥
page.visual_effect vis⇥
ROUTES
map [resources, resource map[rs,r,
with_options, catch_all] wo,ca]?⇥
RSPEC
Run focused example ⌘⇧R
Run behaviour descript. ⌘R
Run BD of select. files/dir ⌥⌘R
describe “description” des⇥
describe Type dest⇥
descript Type, “descript.” dests⇥
describe Controller desc⇥
describe REST Controller desrc⇥
it “should ..” do .. end it⇥
before :each do .. end bef⇥
after :each do .. end aft⇥
Custom matcher block mat⇥
target.should [someth]+ sh[=s]+⇥
target.should_not [sth]+ shn[=s]+⇥
var = mock(“name”) moc⇥
Require spec_helper resh⇥
controller_name :name conn⇥
Story block st⇥
VIEW
Refactor select. to partial ⌃⇧H
form_for [with errors] ff[e]⇥
f.method (snippet name) f.⇥
[form, submit,[f,s,is]t⇥
image_submit]_tag[f,s,is]t⇥
link_to [something]+ li[s]+⇥
If .. for .. end else .. end for⇥
<% end %> end⇥
javascript_include_tag jit⇥
stylesheet_link_tag slt⇥
WEBRAT
attach_file name, “path” atf⇥
click_… ʻ…ʼ cli⇥
fill_in ʻnameʼ, :with ʻvalueʼ fil⇥
save_and_open_page sav⇥
select ʻ..ʼ {.., :from => ʻ..ʼ} sel⇥
TextMate Ruby/Rails/SQL/YAML Cheat Sheet
TextMate Ruby/Rails/SQL/YAML Cheat Sheet