Skip to content

Instantly share code, notes, and snippets.

@jasonm23
Last active December 22, 2015 01:28
Show Gist options
  • Save jasonm23/6396154 to your computer and use it in GitHub Desktop.
Save jasonm23/6396154 to your computer and use it in GitHub Desktop.

Rails - Snippets Quick Reference

$L

$LABEL

fi

<%= Fixtures.identify(:symbol) %>

ft

form_tag

anaf

accepts_nested_attributes_for

arc

Active Record model

aftc

after_create

aftd

after_destroy

afts

after_save

aftu

after_update

aftv

after_validation

aftvoc

after_validation on create

aftvou

after_validation on update

asg

assert(var = assigns(:var))

asd

assert_difference

asnd

assert_no_difference

artnp

assert_redirected_to (nested path)

artnpp

assert_redirected_to (nested path plural)

artp

assert_redirected_to (path)

artpp

assert_redirected_to (path plural)

ass

assert_select

befc

before_create

befd

before_destroy

befs

before_save

befu

before_update

befv

before_validation

befvoc

before_validation on create

befvou

before_validation on update

bt

belongs_to

crw

cattr_accessor

class

class NAME end

tcbi

Table column binary

tcb

Table column boolean

con

Create controller class

tcda

Table column date

tcdt

Table column datetime

tcd

Table column decimal

tcf

Table column float

cla

Create functional test class

tci

Table column integer

tcl

Table column lock_version

tcr

Table column(s) references

tcs

Table column string

tct

Table column text

tcti

Table column time

tcts

Table column timestamp

tctss

Table column timestamps

crud

crud actions

defcreate

def create - resource

deftg

def test_should_get_action

deftp

def test_should_post_action

end

end (ERB)

fina

find(:all)

finf

find(:first)

fini

find(id)

fp

find(params[:id])

for

for loop in rhtml

ffcb

form_for check_box

f.

f.check_box (ffcb)

ffff

form_for file_field

f.

f.file_field (ffff)

ffhf

form_for hidden_field

f.

f.hidden_field (ffhf)

ffl

form_for label

f.

f.label (ffl)

ffpf

form_for password_field

f.

f.password_field (ffpf)

ffrb

form_for radio_box

f.

f.radio_box (ffrb)

ffs

form_for submit

f.

f.submit (ffs)

ffta

form_for text_area

f.

f.text_area (ffta)

fftf

form_for text_field

f.

f.text_field (fftf)

ffe

form_for with errors

ff

form_for

habtm

has_and_belongs_to_many

hm

has_many

hmt

has_many (through)

hmd

has_many dependent: :destroy

ho

has_one

hot

has_one through

ist

image_submit_tag

defi

Define initializer method

jit

javascript_include_tag

lia

link_to (action)

liai

link_to (action, id)

lic

link_to (controller)

lica

link_to (controller, action)

licai

link_to (controller, action, id)

linp

link_to (nested path)

linpp

link_to (nested path plural)

lip

link_to (path)

lipp

link_to (path plural)

lim

link_to model

logd

logger.debug

loge

logger.error

logf

logger.fatal

logi

logger.info

logw

logger.warn

mp

map(&:sym_proc)

mrw

mattr_accessor

mcol

Add Column

mind

Add Index

mcol

Change Column

mcol

Create Column in Table

mccc

Create Several Columns in Table

mtab

Create Table

mtab

Drop Table

mcol

Remove Column

mind

Remove Index

mcol

Rename Column

lsc

lambda

flash

flash[…]

rdb

RAILS_DEFAULT_LOGGER.debug

rea

redirect_to (action)

reai

redirect_to (action, id)

rec

redirect_to (controller)

reca

redirect_to (controller, action)

recai

redirect_to (controller, action, id)

renp

redirect_to (nested path)

renpp

redirect_to (nested path plural)

rep

redirect_to (path)

repp

redirect_to (path plural)

ra

render (action)

ral

render (action, layout)

rf

render (file)

rfu

render (file, use_full_path)

ri

render (inline)

ril

render (inline, locals)

rit

render (inline, type)

rl

render (layout)

rn

render (nothing)

rns

render (nothing, status)

rp

render partial

rpc

render (partial, collection)

rpo

render (partial, object)

rps

render (partial, status)

rt

render (text)

rtl

render (text, layout)

rtlt

render (text, layout: true)

rts

render (text, status)

ru

render (update)

rest

respond_to

returning

returning do |variable| … end

reso

resources :name, only: [:actions]

res

resources :resource_name

resd

resources with an empty params block

resdc

resources with a custom collection block

resdm

resources with a custom member block

sc

scope

scar

scope with arguments

slt

stylesheet_link_tag

st

submit_tag

t.

t.binary (tcbi)

t.

t.boolean (tcb)

t.

t.date (tcda)

t.

t.datetime (tcdt)

t.

t.decimal (tcd)

t.

t.float (tcf)

t.

t.integer (tci)

t.

t.lock_version (tcl)

t.

t.references (tcr)

t.

t.rename (tre)

t.

t.string (tcs)

t.

t.text (tct)

t.

t.time (tcti)

t.

t.timestamp (tcts)

t.

t.timestamps (tctss)

tre

Table column(s) rename

art

assert_redirected_to

asre

assert_response

vaoif

validates_acceptance_of if

vao

validates_acceptance_of

va

validates_associated

vaif

validates_associated if

vc

validates_confirmation_of

vcif

validates_confirmation_of if

ve

validates_exclusion_of

veif

validates_exclusion_of if

vfif

validates_format_of if

vf

validates_format_of

viif

validates_inclusion_of if

vi

validates_inclusion_of

vl

validates_length_of

vlif

validates_length_of if

vnif

validates_numericality_of if

vn

validates_numericality_of

vp

validates_presence_of

vpif

validates_presence_of if

vu

validates_uniqueness_of

vuif

validates_uniqueness_of if

verify

verify — render

verify

verify — redirect

format

format.format

xdelete

xhr delete

xget

xhr get

xpost

xhr post

xput

xhr put

Generated by Sublime Snippet Import to Yasnippet, Powered by tea, figs and ruby

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment