Rails Activerecord Associations

bt - belongs_to ...

belongs_to :${1:category}$0

ho - has_one ...

has_one :${1:article}$0

hm - has_many ...

has_many :${1:comments}$0

habtm - has_and_belongs_to_many ...

has_and_belongs_to_many :${1:roles}$0

Rails Activerecord Basic

cond - :conditions => ...

:conditions => ${1:rails conditions string or array}

Rails Activerecord Validations

vao - validates_acceptance_of ...

validates_acceptance_of :${1:attribute}$0

va - validates_associated ...

validates_associated :${1:attribute}$0

vco - validates_confirmation_of ...

validates_confirmation_of :${1:attribute}$0

ve - validates_each ... Validates each attribute against a block

validates_each :${1:attribute} do |record, attr, value|
  record.errors.add attr, "${2:message}" if $0
end

veo - validates_exclusion_of ... Validates that the value of the specified attribute is not in a particular enumerable object

validates_exclusion_of :${1:attribute},
                       :in => $0

vfo - validates_format_of ... Validates whether the value of the specified attribute is of the correct form by matching it against the regular expression provided

validates_format_of :${1:attribute},
                    :with$0

vio - validates_inclusion_of ... Validates whether the value of the specified attribute is available in a particular enumerable object.

validates_inclusion_of :${1:attribute},
                       :in$0

vlo - validates_length_of ... Validates that the specified attribute matches the length restrictions supplied. Only one option can be used at a time

validates_length_of :${1:attribute},
                    :${2:maximum, minimum, is or within}

vno - validates_numericality_of ... Validates whether the value of the specified attribute is numeric

validates_numericality_of :${1:attribute}$0

vpo - validates_presence_of ... Validates that the specified attributes are not blank

validates_presence_of :${1:attribute}$0

on - :on ... Specifies when this validation is active (default is :save, other options :create, :update)

:on => :${1:default is save, other options are create or update}$0

vifp - :if => Proc.new ... Specifies a proc to call to determine if the validation should occur

:if => Proc.new {|instance| ${1:some code that checks your instance}$0

vif - :if => :method_name ... Specifies a method to call to determine if the validation should occur

:if => :${1:method_name}

blank - :allow_blank ... If set to true, skips this validation if the attribute is blank

:allow_blank => ${1:false}

vnil - :allow_nil ... Skip validation if attribute is nil

:allow_nil => ${1:false}$0

msg - :message ... A custom error message

:message => "${1:message}"$0

tl - :too_long ... The error message if the attribute goes over the maximum for validates_length_of

:too_long => "${1:value is too long (maximum is %d characters)}"$0

ts - :too_short ... The error message if the attribute goes under the minimum for validates_length_of

:too_short => "${1:value is too short (minimum is %d characters)}"$0

wl - :wrong_length ... The error message if using the :is method and the attribute is the wrong size for validates_length_of

:wrong_length => "${1:value has wrong length (should be %d characters)}"$0

accept - :accept ... Specifies value that is considered accepted. The default value is a string "1" for validates_acceptance_of

:accept => "${1:1}"$0

with - :with ... The regular expression used to validate the format with for validates_format_of

:with => /^${1:regexp}\$/$0

in - :in ... Specify an enumerable object of available items validates_inclusion/exclusion_of

:in => $0

is - :is ... The exact size of the attribute for validates_length_of

:is => ${1:12}

max - :maximum ... Specifies the maximum value for validates_length_of

:maximum => ${1:12}

min - :minimum ... Specifies the minimum value for validates_length_of

:minimum => ${1:12}

within - :within ... A range specifying the minimum and maximum size of the attribute for validates_length_of

:within => (${1:12}..${2:15})$0

oi - :only_integer for validates_numericality

:only_integer => ${1:true}$0

gt - :greater_than ... Specifies the value must be greater than the supplied value for validates_numericality_of

:greater_than => ${1:5}$0

gtet - :greater_than_or_equal_to ... Specifies the value must be greater than or equal the supplied value for validates_numericality_of

:greater_than_or_equal_to => ${1:5}$0

et - :equal_to ... Specifies the value must be equal to the supplied value for validates_numericality_of

:equal_to => ${1:5}$0

lt - :less_than ... Specifies the value must be less than the supplied value for validates_numericality_of

:less_than => ${1:5}$0

ltet - :less_than_or_equal_to ... Specifies the value must be less than or equal the supplied value for validates_numericality_of

:less_than_or_equal_to => ${1:5}$0

odd - :odd ... Specifies the value must be an odd number for validates_numericality_of

:odd => true

even - :even ... Specifies the value must be an even number for validates_numericality_of

:even => true

Rails Controllers Basic

bf - before_filter ...

before_filter :${1:method_name}$0

only - :only => [...] ... before_filter condition

:only => [:${1:create, }

Rhtml Basic

confirm - :confirm ... JavaScript confirm message

:confirm => '${1:Are you sure?}'$0

cai - :controller, :action, :id for urls

:controller => :${1:posts}, :action => :${2:show}, :id => ${3:post}

img - image_tag

<%= image_tag '$1' %>$0

imgt - image_tag with title

<%= image_tag '$2', :title => "$1" %>$0

jit - javascript include tag

<%= javascript_include_tag ${1:defaults} %>$0

slt - stylesheet link tag

<%= stylesheet_link_tag '${1:style}' %>$0

lt - link to

<%= link_to '$1', $0 %>

ltr - link to remote

<%= link_to_remote '$1', :url => { $2 }$3 %>$0

partial - render :partial ...

<%= render :partial => '${1:item}'$0 %>

Rhtml Forms

ft - form tag

<% form_tag $1do %>
        $0
<% end %>

ftm - form tag with method

<% form_tag $2, :method => ${1:post} do %>
        $0
<% end %>

ll - html label

<label>$0</label>

lf - html label for

<label for="$1">$0</label>

emf - error messages for

<%= error_messages_for( :$1 ) %>$0

pf - password field

<%= password_field :${1:model}, :${2:attribute} %>$0

st - submit tag

<%= submit_tag '${1:save}' %>$0

tf - text field

<%= text_field :${1:model}, :${2:attribute} %>$0

hf - hidden field

<%= hidden_field :${1:model}, :${2:attribute} %>$0

cb - checkbox

<%= check_box :${1:model}, :${2:attribute} %>$0

select - select field

<%= select :${1:model}, :${2:attribute}, ${3:values}, {:include_blank => true} %>$0

Rhtml Html

< - HTML: tag

<${1:div}>
        $0
</${1}

divc - HTML: div with class

<div class="$1">
        $0
</div>

divi - HTML: div with id

<div id="$1">
        $0
</div>

br - HTML: line break

<br/>
$0

table - HTML: table

<table class="$1">
        <tr>
                <th>$0</th>
        </tr>
</table>

td - HTML: table cell

<td>$0</td>

tr - HTML: table row

<tr>
        $0
</tr>

troe - HTML: table row class odd-even

<tr class="<%= cycle( 'odd', 'even' ) %>">
        $0
</tr>

ulc - HTML: unordered list with class

<ul class="${1:list}">
        $0
</ul>

ul - HTML: unordered list

<ul>
        $0
</ul>

li - HTML: list item

<li>$1</li>$0

Rhtml Ruby

= - <%= block result %>

<%= $0 %>

% - <% ruby code block -%>

<% $0 -%>

do - do .. end

do
        $0
end

doo - do |object| .. end

do |${1:object}|
        $0
end

eacho - each do item

<% ${1:@list}.each do |${2:item}| do %>
        $0
<% end %>

forin - for .. in .. end

<%= for ${1:element} in ${2:collection}
        ${1:element}.$0
end %>

if - if statement

<% if ${1:logged_in?} %>
        $0
<% end %>

ife - if ... else ... end

<% if ${1:logged_in?} %>
        $0
<% else %>
        
<% end %>

end - end tag

<% end %>

Ruby Basic

begin - begin .. rescue .. end

begin
        $1
rescue ${2:Exception} => ${3:e}
        $0
end

class - class .. end

class ${1:class_name}
        $0
end

def - def .. end

def ${1:method_name}
        $0
end

defc - def .. end with comment

#
# ${2:comment}
#
def ${1:method_name}
        $0
end

defs - def self.method_name .. end

def self.${1:method_name}
        $0
end

defr - def .. rescue .. end

def ${1:method_name}
        $0
rescue ${2:ErrorClass }=> err
  
end

do - do .. end

do
        $0
end

doo - do |object| .. end

do |${1:object}|
        $0
end

ife - if .. else .. end

if ${1:condition}
        $2
else
        $3
end

if - if .. end

if ${1:condition}
        $0
end

elsif - elsif ..

elsif ${1:condition}
  $0

unless - unless

unless ${1:condition}
        $0
end

case - case .. end

case ${1:object}
        when ${2:condition}
                $0
end

when - when

when ${1:condition}
        $0

else - else ...

else
  $0

Ruby Collections

: - :key => "value" - hash pair

:${1:key} => ${2:"value"}$0

- hash rocket

 =>

collect - collect element

collect { |${1:element}| ${1:element}.$0 }

collecto - collect element do

collect do |${1:element}|
        ${1:element}.$0
end

each - each element

each { |${1:element}| ${1:element}.$0 }

eacho - each element do

each do |${1:element}|
        ${1:element}.$0
end

ewi - each_with_index

each_with_index { |${1:element}, ${2:idx}| ${1:element}.$0 }

ewio - each_with_index do

each_with_index do |${1:element}, ${2:idx}|
        ${1:element}.$0
end

forin - for .. in .. end

for ${1:element} in ${2:collection}
        ${1:element}.$0
end

inject - inject object

inject(${1:object}) { |${2:injection}, ${3:element}| $0 }

injecto - inject object do

inject(${1:object}) do |${2:injection}, ${3:element}| 
        $0
end

reject - reject element

reject { |${1:element}| ${1:element}.$0 }

rejecto - reject element do

reject do |${1:element}| 
        ${1:element}.$0
end

select - select element

select { |${1:element}| ${1:element}.$0 }

selecto - select element do

select do |${1:element}|
        ${1:element}.$0
end

fa - find_all elements

find_all { |${1:element}| ${1:element}.$0 }

fao - find_all elements do

find_all do |${1:element}|
        ${1:element}.$0
end

any - any element

any? { |${1:element}| ${1:element}.$0 }

anyo - any element do

any? do |${1:element}|
        ${1:element}.$0
end

all - all elements?

all? { |${1:element}| ${1:element}.$0 }

allo - all elements? do

all? do |${1:element}|
        ${1:element}.$0
end

map - map elements

map { |${1:element}| ${1:element}.$0 }

mapo - map elements do

map do |${1:element}|
        ${1:element}.$0
end

Shoulda Actioncontroller

sat - should_assign_to ...

should_assign_to ${1:attribute}$0

sfp - should_filter_params ...

should_filter_params ${1:attribute}$0

snat - should_not_assign_to ...

should_not_assign_to ${1:attribute}$0

snstf - should_not_set_the_flash

should_not_set_the_flash$0

srt - should_redirect_to ...

should_redirect_to('${1:description}') { $0 }

srt - should_render_template ...

should_render_template ${1:template}$0

srwl - should_render_with_layout ...

should_render_with_layout ${1:layout}$0

srwl - should_render_without_layout ...

should_render_without_layout ${1:layout}$0

srw - should_respond_with ...

should_respond_with ${1:status}$0

srwct - should_respond_with_content_type ...

should_respond_with_content_type ${1:content_type_or_regexp}$0

sr - should_route ...

should_route :${1:get}, "${$2:path}", $0

sss - should_set_session ...

should_set_session('${1:key}') { $0 }

sstft - should_set_the_flash_to ...

should_set_the_flash_to ${1:string_or_regexp}$0

Shoulda Activerecord

samao - should_allow_mass_assignment_of ...

should_allow_mass_assignment_of :${1:attributes}$0

snamao - should_not_allow_mass_assignment_of ...

should_not_allow_mass_assignment_of :${1:attributes}$0

shcm - should_have_class_methods ...

should_have_class_methods :${1:attributes}$0

shim - should_have_instance_methods ...

should_have_instance_methods :${1:attributes}$0

shdc - should_have_db_columns ...

should_have_db_columns :${1:attributes}$0

shi - should_have_index ...

should_have_index :${1:attributes}$0

shns - should_have_named_scope ...

should_have_named_scope :${1:scope_call}, $0

shrm - should_have_readonly_methods ...

should_have_readonly_methods :${1:attributes}$0

sbt - should_belong_to ...

should_belong_to :${1:associations}$0

shm - should_have_many ...

should_have_many :${1:associations}$0

sho - should_have_one ...

should_have_one :${1:associations}$0

shabtm - should_have_and_belong_to_many ...

should_have_and_belong_to_many :${1:associations}$0

savf - should_allow_values_for ...

should_allow_values_for :${1:attribute}, ${2:values}$0

snavf - should_not_allow_values_for ...

should_not_allow_values_for :${1:attribute}, ${2:values}$0

selal - should_ensure_length_at_least ...

should_ensure_length_at_least :${1:attribute}, ${2:minimum_length}$0

selir - should_ensure_length_in_range ...

should_ensure_length_in_range :${1:attribute}, (${2:minimum_length}..${3:maximum_length})$0

seli - should_ensure_length_is ...

should_ensure_length_is :${1:attribute}, ${2:length}$0

sevir - should_ensure_value_in_range ...

should_ensure_value_in_range :${1:attribute}, (${2:minimum_length}..${3:maximum_length})$0

svao - should_validate_acceptance_of ...

should_validate_acceptance_of :${1:attributes}$0

svno - should_validate_numericality_of ...

should_validate_numericality_of :${1:attributes}$0

svpo - should_validate_presence_of ...

should_validate_presence_of :${1:attributes}$0

svuo - should_validate_uniqueness_of ...

should_validate_uniqueness_of :${1:attributes}, :scoped_to => ${2:field to scope uniq check}$0

Shoulda Basic

context - context "xyz" do ... end

context "${1:Name}" do
        $0
end

setup - setup do ... end

setup do
        $0
end

Snippet Tools

snip - New snippet

<snippet>
  <text><![CDATA[$1]]></text>
  <tag>$2</tag>
  <description>$3</description>
</snippet>$0

snippets - New snippet

<?xml version='1.0' encoding='utf-8'?>
<snippets language="${1:ruby}">
        $0
</snippets>

c - Short Comment

<!-- $1 -->$0

lc - Long comment

<!--
                $1
-->$0