Skip to content

Instantly share code, notes, and snippets.

@ches
Created December 2, 2010 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ches/724533 to your computer and use it in GitHub Desktop.
Save ches/724533 to your computer and use it in GitHub Desktop.
UltiSnips snippets derived from converting Ruby on Rails TextMate bundle
# TextMate added these variables to cope with changes in ERB handling
# in different versions of Rails -- for instance, Rails 3 automatically
# strips whitespace so that it's no longer necessary to use a form like
# <% end -%>, but if you're still maintaining Rails 2 projects, you
# can't omit the minus sign and get the same behavior.
#
# The following regex replace substitutes the function below for the
# TextMate variable references after the snippets are converted:
#
# /\v\$\{(TM_RAILS_TEMPLATE_([^_]+)_RUBY_([^_\s]+))\}/`!p textmate_var('\1', snip)`/g
#
global !p
def textmate_var(var, snip):
lookup = dict(
TM_RAILS_TEMPLATE_START_RUBY_EXPR = snip.opt('g:tm_rails_template_start_ruby_expr', '<%= '),
TM_RAILS_TEMPLATE_END_RUBY_EXPR = snip.opt('g:tm_rails_template_end_ruby_expr', ' %>'),
TM_RAILS_TEMPLATE_START_RUBY_INLINE = snip.opt('g:tm_rails_template_start_ruby_inline', ' %>'),
TM_RAILS_TEMPLATE_END_RUBY_INLINE = snip.opt('g:tm_rails_template_end_ruby_inline', ' %>'),
TM_RAILS_TEMPLATE_END_RUBY_BLOCK = 'end'
)
snip.rv = lookup[var]
return
endglobal
###########################################################################
# GENERATED FROM get_tm_snippets.py + REGEX REPLACE #
###########################################################################
snippet fi "<%= Fixtures.identify(:symbol) %>"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`Fixtures.identify(:${1:name})`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`$0
endsnippet
snippet ft "form_tag"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_INLINE', snip)`form_tag(${1::action => "${5:update}"}${6:, {:${8:class} => "${9:form}"\}}) do`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
$0
`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_BLOCK', snip)`
endsnippet
snippet end "end (ERB)"
<% end -%>
endsnippet
snippet for "for loop (ERB)"
<% if !${1:list}.blank? %>
<% for ${2:item} in ${1} %>
$3
<% end %>
<% else %>
$4
<% end %>
endsnippet
snippet ffcb "form_for check_box"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.check_box :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet ffff "form_for file_field 2"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.file_field :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet ffhf "form_for hidden_field 2"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.hidden_field :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet ffl "form_for label 2"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR}f.label :${1:attribute', snip)`${2:, "${3:${1/[[:alpha:]]+|(_)/(?1: :\u$0)/g}}"}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet ffpf "form_for password_field 2"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.password_field :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet ffrb "form_for radio_box 2"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.radio_box :${1:attribute}, :${2:tag_value}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet ffs "form_for submit 2"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.submit "${1:Submit}"${2:, :disable_with => '${3:$1ing...}'}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet ffta "form_for text_area 2"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.text_area :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet fftf "form_for text_field 2"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.text_field :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet fields "fields_for"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_INLINE', snip)`fields_for :${1:model}, @${2:$1} do |$1|`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_INLINE', snip)`
$0
`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_BLOCK', snip)`
endsnippet
snippet f. "f_fields_for (nff)"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_INLINE', snip)`f.fields_for :${1:attribute} do |${2:f}|`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_INLINE', snip)`
$0
`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_BLOCK', snip)`
endsnippet
snippet f. "f.checkbox"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.check_box :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet f. "f.file_field"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.file_field :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet f. "f.hidden_field"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.hidden_field :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet f. "f.label"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR}f.label :${1:attribute', snip)`${2:, "${3:${1/[[:alpha:]]+|(_)/(?1: :\u$0)/g}}"}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet f. "f.password_field"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.password_field :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet f. "f.radio_box"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.radio_box :${1:attribute}, :${2:tag_value}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet f. "f.submit"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.submit "${1:Submit}"${2:, :disable_with => '${3:$1ing...}'}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet f. "f.text_area"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.text_area :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet f. "f.text_field"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`f.text_field :${1:attribute}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet ffe "form_for with errors"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`error_messages_for :${1:model}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_INLINE', snip)`form_for @${2:$1} do |f|`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_INLINE', snip)`
$0
`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_BLOCK', snip)`
endsnippet
snippet ff "form_for"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_INLINE', snip)`form_for @${1:model} do |f|`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_INLINE', snip)`
$0
`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_BLOCK', snip)`
endsnippet
snippet ist "image_submit_tag"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`image_submit_tag("${1:agree.png}"${2:${3:, :id => "${4:${1/^(\w+)(\.\w*)?$/$1/}}"}${5:, :name => "${6:${1/^(\w+)(\.\w*)?$/$1/}}"}${7:, :class => "${8:${1/^(\w+)(\.\w*)?$/$1/}-button}"}${9:, :disabled => ${10:false}}})`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet it "image_tag"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`image_tag "$1${2:.png}"${3:${4:, :title => "${5:title}"}${6:, :class => "${7:class}"}}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet layout "layout"
layout "${1:template_name}"${2:${3:, :only => ${4:[:${5:action}, :${6:action}]}}${7:, :except => ${8:[:${9:action}, :${10:action}]}}}
endsnippet
snippet jit "javascript_include_tag"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`javascript_include_tag ${1::all}${2:, :cache => ${3:true}}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet lia "link_to (action)"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to "${1:link text...}", :action => "${2:index}"`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet liai "link_to (action, id)"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to "${1:link text...}", :action => "${2:edit}", :id => ${3:@item}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet lic "link_to (controller)"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to "${1:link text...}", :controller => "${2:items}"`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet lica "link_to (controller, action)"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to "${1:link text...}", :controller => "${2:items}", :action => "${3:index}"`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet licai "link_to (controller, action, id)"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to "${1:link text...}", :controller => "${2:items}", :action => "${3:edit}", :id => ${4:@item}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet linpp "link_to (nested path plural)"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to ${1:"${2:link text...}"}, ${3:${10:parent}_${11:child}_path(${12:@}${13:${10}})}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet linp "link_to (nested path)"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to ${1:"${2:link text...}"}, ${3:${12:parent}_${13:child}_path(${14:@}${15:${12}}, ${16:@}${17:${13}})}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet lipp "link_to (path plural)"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to ${1:"${2:link text...}"}, ${3:${4:model}s_path}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet lip "link_to (path)"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to ${1:"${2:link text...}"}, ${3:${12:model}_path(${13:@}${14:${12}})}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet lim "link_to model"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to ${1:model}.${2:name}, ${3:${4:$1}_path(${14:$1})}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet hide "page.hide (*ids)"
page.hide ${1:"${2:id(s)}"}
endsnippet
snippet ins "page.insert_html (position, id, partial)"
page.insert_html :${1:top}, ${2:"${3:id}"}, :${4:partial => "${5:template}"}
endsnippet
snippet rep "page.replace (id, partial)"
page.replace ${1:"${2:id}"}, :${3:partial => "${4:template}"}
endsnippet
snippet reph "page.replace_html (id, partial)"
page.replace_html ${1:"${2:id}"}, :${3:partial => "${4:template}"}
endsnippet
snippet show "page.show (*ids)"
page.show ${1:"${2:id(s)}"}
endsnippet
snippet tog "page.toggle (*ids)"
page.toggle ${1:"${2:id(s)}"}
endsnippet
snippet vis "page.visual_effect (effect, id)"
page.visual_effect :${1:toggle_slide}, ${2:"${3:DOM ID}"}
endsnippet
snippet rp "render (partial) (rp)"
render :partial => "${1:item}"
endsnippet
snippet rpc "render (partial,collection) (rpc)"
render :partial => "${1:item}", :collection => ${2:@$1s}
endsnippet
snippet rpl "render (partial,locals) (rpl)"
render :partial => "${1:item}", :locals => { :${2:$1} => ${3:@$1}$0 }
endsnippet
snippet rpo "render (partial,object) (rpo)"
render :partial => "${1:item}", :object => ${2:@$1}
endsnippet
snippet rps "render (partial,status) (rps)"
render :partial => "${1:item}", :status => ${2:500}
endsnippet
snippet slt "stylesheet_link_tag"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`stylesheet_link_tag {1::all}${2:, :cache => ${3:true}}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet st "submit_tag"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`submit_tag "${1:Save changes}"${2:, :id => "${3:submit}"}${4:, :name => "${5:$3}"}${6:, :class => "${7:form_$3}"}${8:, :disabled => ${9:false}}${10:, :disable_with => "${11:Please wait...}"}`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
snippet else "else (ERB)"
<% else %>
endsnippet
snippet if "if (ERB)"
<% if ${1:condition} %>$0
endsnippet
snippet lf "link_to_function"
`!p textmate_var('TM_RAILS_TEMPLATE_START_RUBY_EXPR', snip)`link_to_function ${1:"${2:Greeting}"}, "${3:alert('Hello world!')}"$4`!p textmate_var('TM_RAILS_TEMPLATE_END_RUBY_EXPR', snip)`
endsnippet
###########################################################################
# GENERATED FROM get_tm_snippets.py #
###########################################################################
snippet anaf "accepts_nested_attributes_for"
accepts_nested_attributes_for :${1:association_name}${2:${3:, :allow_destroy => true}${4:, :reject_if => proc { |obj| ${5:obj.blank?} \}}}
endsnippet
snippet tcbi "Create binary column"
t.binary :${1:title}${2:, :limit => ${3:2}.megabytes}
$0
endsnippet
snippet tcb "Create boolean column"
t.boolean :${1:title}
$0
endsnippet
snippet cla "Create controller class"
class ${1:Model}Controller < ApplicationController
before_filter :find_${2:model}
$0
private
def find_${2}
@$2 = ${3:$1}.find(params[:id]) if params[:id]
end
end
endsnippet
snippet tcda "Create date column"
t.date :${1:title}
$0
endsnippet
snippet tcdt "Create datetime column"
t.datetime :${1:title}
$0
endsnippet
snippet tcd "Create decimal column"
t.decimal :${1:title}${2:${3:, :precision => ${4:10}}${5:, :scale => ${6:2}}}
$0
endsnippet
snippet tcf "Create float column"
t.float :${1:title}
$0
endsnippet
snippet cla "Create functional test class"
require 'test_helper'
class ${1:Model}ControllerTest < ActionController::TestCase
test$0
end
endsnippet
snippet tci "Create integer column"
t.integer :${1:title}
$0
endsnippet
snippet tcl "Create lock_version column"
t.integer :lock_version, :null => false, :default => 0
$0
endsnippet
# FIXME: handling literal bracket pair inside of nested tab groups?
snippet tcr "Create references column"
t.references :${1:taggable}${2:, :polymorphic => ${3:{ :default => '${4:Photo}' \}}}
$0
endsnippet
snippet resources "Create resources controller class"
class ${1:Model}sController < ApplicationController
before_filter :find_${1/./\l$0/}, :only => [:show, :edit, :update, :destroy]
# GET /${1/./\l$0/}s
# GET /${1/./\l$0/}s.xml
def index
@${1/./\l$0/}s = ${1:Model}.all
respond_to do |wants|
wants.html # index.html.erb
wants.xml { render :xml => @${1/./\l$0/}s }
end
end
# GET /${1/./\l$0/}s/1
# GET /${1/./\l$0/}s/1.xml
def show
respond_to do |wants|
wants.html # show.html.erb
wants.xml { render :xml => @${1/./\l$0/} }
end
end
# GET /${1/./\l$0/}s/new
# GET /${1/./\l$0/}s/new.xml
def new
@${1/./\l$0/} = ${1:Model}.new
respond_to do |wants|
wants.html # new.html.erb
wants.xml { render :xml => @${1/./\l$0/} }
end
end
# GET /${1/./\l$0/}s/1/edit
def edit
end
# POST /${1/./\l$0/}s
# POST /${1/./\l$0/}s.xml
def create
@${1/./\l$0/} = ${1:Model}.new(params[:${1/./\l$0/}])
respond_to do |wants|
if @${1/./\l$0/}.save
flash[:notice] = '${1:Model} was successfully created.'
wants.html { redirect_to(@${1/./\l$0/}) }
wants.xml { render :xml => @${1/./\l$0/}, :status => :created, :location => @${1/./\l$0/} }
else
wants.html { render :action => "new" }
wants.xml { render :xml => @${1/./\l$0/}.errors, :status => :unprocessable_entity }
end
end
end
# PUT /${1/./\l$0/}s/1
# PUT /${1/./\l$0/}s/1.xml
def update
respond_to do |wants|
if @${1/./\l$0/}.update_attributes(params[:${1/./\l$0/}])
flash[:notice] = '${1:Model} was successfully updated.'
wants.html { redirect_to(@${1/./\l$0/}) }
wants.xml { head :ok }
else
wants.html { render :action => "edit" }
wants.xml { render :xml => @${1/./\l$0/}.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /${1/./\l$0/}s/1
# DELETE /${1/./\l$0/}s/1.xml
def destroy
@${1/./\l$0/}.destroy
respond_to do |wants|
wants.html { redirect_to(${1/./\l$0/}s_url) }
wants.xml { head :ok }
end
end
private
def find_${1/./\l$0/}
@${1/./\l$0/} = ${1:Model}.find(params[:id])
end
end
endsnippet
snippet tcs "Create string column"
t.string :${1:title}
$0
endsnippet
snippet tct "Create text column"
t.text :${1:title}
$0
endsnippet
snippet tcti "Create time column"
t.time :${1:title}
$0
endsnippet
snippet tcts "Create timestamp column"
t.timestamp :${1:title}
$0
endsnippet
snippet tctss "Create timestamps columns"
t.timestamps
$0
endsnippet
snippet mcol "Migration Create Column (mcc)"
t.column ${1:title}, :${2:string}
$0
endsnippet
snippet mccc "Migration Create Column Continue (mccc)"
t.column ${1:title}, :${2:string}
mccc$0
endsnippet
snippet mtab "Migration Drop Create Table (mdct)"
drop_table :${1:table}${2: [press tab twice to generate create_table]}
endsnippet
snippet mcol "Migration Remove and Add Column (mrac)"
remove_column :${1:table}, :${2:column}${3: [press tab twice to generate add_column]}
endsnippet
snippet rdb "RAILS_DEFAULT_LOGGER.debug (rdb)"
RAILS_DEFAULT_LOGGER.debug "${1:message}"$0
endsnippet
snippet tre "Table column(s) rename"
t.rename(:${1:old_column_name}, :${2:new_column_name})
$0
endsnippet
snippet art "Test Assert Redirected To (art)"
assert_redirected_to ${2::action => "${1:index}"}
endsnippet
snippet asre "Test Assert Response (are)"
assert_response :${1:success}, @response.body$0
endsnippet
snippet aftc "after_create"
after_create
endsnippet
snippet aftd "after_destroy"
after_destroy
endsnippet
snippet afts "after_save"
after_save
endsnippet
snippet aftu "after_update"
after_update
endsnippet
snippet aftv "after_validation"
after_validation
endsnippet
snippet aftvoc "after_validation_on_create"
after_validation_on_create
endsnippet
snippet aftvou "after_validation_on_update"
after_validation_on_update
endsnippet
snippet asg "assert(var = assigns(:var))"
assert(${1:var} = assigns(:${1}), "Cannot find @${1}")
$0
endsnippet
snippet asd "assert_difference"
assert_difference "${1:Model}.${2:count}", ${3:1} do
$0
end
endsnippet
snippet asnd "assert_no_difference"
assert_no_difference "${1:Model}.${2:count}" do
$0
end
endsnippet
snippet artnpp "assert_redirected_to (nested path plural)"
assert_redirected_to ${10:${2:parent}_${3:child}_path(${4:@}${5:${2}})}
endsnippet
snippet artnp "assert_redirected_to (nested path)"
assert_redirected_to ${2:${12:parent}_${13:child}_path(${14:@}${15:${12}}, ${16:@}${17:${13}})}
endsnippet
snippet artpp "assert_redirected_to (path plural)"
assert_redirected_to ${10:${2:model}s_path}
endsnippet
snippet artp "assert_redirected_to (path)"
assert_redirected_to ${2:${12:model}_path(${13:@}${14:${12}})}
endsnippet
snippet asrj "assert_rjs"
assert_rjs :${1:replace}, ${2:"${3:dom id}"}
endsnippet
snippet ass "assert_select"
assert_select '${1:path}'${2:, :${3:text} => ${4:'${5:inner_html}'}}${6: do
$0
end}
endsnippet
snippet befc "before_create"
before_create
endsnippet
snippet befd "before_destroy"
before_destroy
endsnippet
snippet befs "before_save"
before_save
endsnippet
snippet befu "before_update"
before_update
endsnippet
snippet befv "before_validation"
before_validation
endsnippet
snippet befvoc "before_validation_on_create"
before_validation_on_create
endsnippet
snippet befvou "before_validation_on_update"
before_validation_on_update
endsnippet
snippet bt "belongs_to (bt)"
belongs_to :${1:object}${2:, :class_name => "${3:${1/[[:alpha:]]+|(_)/(?1::\u$0)/g}}", :foreign_key => "${4:${1}_id}"}
endsnippet
snippet crw "cattr_accessor"
cattr_accessor :${0:attr_names}
endsnippet
snippet defcreate "def create - resource"
def create
@${1:model} = ${2:${1/[[:alpha:]]+|(_)/(?1::\u$0)/g}}.new(params[:$1])
$0
respond_to do |wants|
if @$1.save
flash[:notice] = '$2 was successfully created.'
wants.html { redirect_to(@$1) }
wants.xml { render :xml => @$1, :status => :created, :location => @$1 }
else
wants.html { render :action => "new" }
wants.xml { render :xml => @$1.errors, :status => :unprocessable_entity }
end
end
end
endsnippet
snippet test "test do..end"
test "${1:something interesting}" do
$0
end
endsnippet
snippet deftg "def get request"
def test_should_get_${1:action}
${2:@${3:model} = ${4:$3s}(:${5:fixture_name})
}get :${1}${6:, :id => @$3.to_param}
assert_response :success
$0
end
endsnippet
snippet deftp "def post request"
def test_should_post_${1:action}
${3:@$2 = ${4:$2s}(:${5:fixture_name})
}post :${1}${6:, :id => @$2.to_param}, :${2:model} => { $0 }
assert_response :redirect
end
endsnippet
snippet fina "find(:all)"
find(:all${1:, :conditions => ['${2:${3:field} = ?}', ${5:true}]})
endsnippet
snippet finf "find(:first)"
find(:first${1:, :conditions => ['${2:${3:field} = ?}', ${5:true}]})
endsnippet
snippet fini "find(id)"
find(${1:id})
endsnippet
snippet fine "find_each"
find_each(${1::conditions => {:${2:field} => ${3:true}\}}) do |${4:${TM_CURRENT_WORD/(\w+)\./\L$1/g}}|
$0
end
endsnippet
snippet finb "find_in_batches"
find_in_batches(${1::conditions => {:${2:field} => ${3:true}\}}) do |${4:${TM_CURRENT_WORD/(\w+)\./\L$1/g}}s|
$4s.each do |$4|
$0
end
end
endsnippet
snippet habtm "has_and_belongs_to_many (habtm)"
has_and_belongs_to_many :${1:object}${2:, :join_table => "${3:table_name}", :foreign_key => "${4:${1}_id}"}
endsnippet
snippet hm "has_many (hm)"
has_many :${1:object}s${2:, :class_name => "${1}", :foreign_key => "${4:reference}_id"}
endsnippet
snippet hmt "has_many (through)"
has_many :${1:objects}, :through => :${2:join_association}${3:, :source => :${4:${2}_table_foreign_key_to_${1}_table}}
endsnippet
snippet hmd "has_many :dependent => :destroy"
has_many :${1:object}s${2:, :class_name => "${1}", :foreign_key => "${4:reference}_id"}, :dependent => :destroy$0
endsnippet
snippet ho "has_one (ho)"
has_one :${1:object}${2:, :class_name => "${3:${1/[[:alpha:]]+|(_)/(?1::\u$0)/g}}", :foreign_key => "${4:${1}_id}"}
endsnippet
snippet logd "logger.debug"
${1:Rails.}logger.debug { "${1:message}" }$0
endsnippet
snippet loge "logger.error"
logger.error { "${1:message}" }$0
endsnippet
snippet logf "logger.fatal"
logger.fatal { "${1:message}" }$0
endsnippet
snippet logi "logger.info"
logger.info { "${1:message}" }$0
endsnippet
snippet logw "logger.warn"
logger.warn { "${1:message}" }$0
endsnippet
snippet mp "map(&:sym_proc)"
map(&:${1:id})
endsnippet
snippet mapca "map.catch_all"
${1:map}.catch_all "*${2:anything}", :controller => "${3:default}", :action => "${4:error}"
endsnippet
snippet map "map.named_route"
${1:map}.${2:connect} '${3::controller/:action/:id}'
endsnippet
snippet mapr "map.resource"
${1:map}.resource :${2:resource}${10: do |${11:$2}|
$0
end}
endsnippet
snippet maprs "map.resources"
${1:map}.resources :${2:resource}${10: do |${11:$2}|
$0
end}
endsnippet
snippet mapwo "map.with_options"
${1:map}.with_options :${2:controller} => '${3:thing}' do |${4:$3}|
$0
end
endsnippet
snippet mrw "mattr_accessor"
mattr_accessor :${0:attr_names}
endsnippet
snippet ncl "named_scope lambda"
named_scope :name, lambda { |${1:param}| { :conditions => ${3:['${4:${5:field} = ?}', ${6:$1}]} } }
endsnippet
snippet nc "named_scope"
named_scope :name${1:, :joins => :${2:table}}, :conditions => ${3:['${4:${5:field} = ?}', ${6:true}]}
endsnippet
snippet dscope "default_scope"
default_scope ${1:order(${2:'${3:created_at DESC}'})}
endsnippet
snippet flash "flash[...]"
flash[:${1:notice}] = "${2:Successfully created...}"$0
endsnippet
snippet rea "redirect_to (action)"
redirect_to :action => "${1:index}"
endsnippet
snippet reai "redirect_to (action, id)"
redirect_to :action => "${1:show}", :id => ${0:@item}
endsnippet
snippet rec "redirect_to (controller)"
redirect_to :controller => "${1:items}"
endsnippet
snippet reca "redirect_to (controller, action)"
redirect_to :controller => "${1:items}", :action => "${2:list}"
endsnippet
snippet recai "redirect_to (controller, action, id)"
redirect_to :controller => "${1:items}", :action => "${2:show}", :id => ${0:@item}
endsnippet
snippet renpp "redirect_to (nested path plural)"
redirect_to(${2:${10:parent}_${11:child}_path(${12:@}${13:${10}})})
endsnippet
snippet renp "redirect_to (nested path)"
redirect_to(${2:${12:parent}_${13:child}_path(${14:@}${15:${12}}, ${16:@}${17:${13}})})
endsnippet
snippet repp "redirect_to (path plural)"
redirect_to(${2:${10:model}s_path})
endsnippet
snippet rep "redirect_to (path)"
redirect_to(${2:${12:model}_path(${13:@}${14:${12}})})
endsnippet
snippet reb "redirect_to :back"
redirect_to :back
endsnippet
snippet ra "render (action)... (ra)"
render :action => "${1:action}"
endsnippet
snippet ral "render (action,layout) (ral)"
render :action => "${1:action}", :layout => "${2:layoutname}"
endsnippet
snippet rf "render (file) (rf)"
render :file => "${1:filepath}"
endsnippet
snippet rfu "render (file,use_full_path) (rfu)"
render :file => "${1:filepath}", :use_full_path => ${2:false}
endsnippet
snippet ri "render (inline) (ri)"
render :inline => "${1:<%= 'hello' %>}"
endsnippet
snippet ril "render (inline,locals) (ril)"
render :inline => "${1:<%= 'hello' %>}", :locals => { ${2::name} => "${3:value}"$4 }
endsnippet
snippet rit "render (inline,type) (rit)"
render :inline => "${1:<%= 'hello' %>}", :type => ${2::rxml}
endsnippet
snippet rl "render (layout) (rl)"
render :layout => "${1:layoutname}"
endsnippet
snippet rn "render (nothing) (rn)"
render :nothing => ${1:true}
endsnippet
snippet rns "render (nothing,status) (rns)"
render :nothing => ${1:true}, :status => ${2:401}
endsnippet
snippet rt "render (text) (rt)"
render :text => "${1:text to render...}"
endsnippet
snippet rtl "render (text,layout) (rtl)"
render :text => "${1:text to render...}", :layout => "${2:layoutname}"
endsnippet
snippet rtlt "render (text,layout => true) (rtlt)"
render :text => "${1:text to render...}", :layout => ${2:true}
endsnippet
snippet rts "render (text,status) (rts)"
render :text => "${1:text to render...}", :status => ${2:401}
endsnippet
snippet ru "render (update)"
render :update do |${2:page}|
$2.$0
end
endsnippet
snippet rest "respond_to"
respond_to do |wants|
wants.${1:html}${2: { $0 \}}
end
endsnippet
snippet resw "respond_with"
respond_with(${1:@${2:model}})${3: do |format|
format.${4:html} { $0 \}
end}
endsnippet
# FIXME
snippet returning "returning do |variable| ... end"
returning ${1:variable} do${2/(^(?<var>\s*[a-z_][a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1: |)/}${2:v}${2/(^(?<var>\s*[a-z_][a-zA-Z0-9_]*\s*)(,\g<var>)*,?\s*$)|.*/(?1:|)/}
$0
end
endsnippet
snippet t. "t.binary (tcbi)"
t.binary :${1:title}${2:, :limit => ${3:2}.megabytes}
t.$0
endsnippet
snippet t. "t.boolean (tcb)"
t.boolean :${1:title}
t.$0
endsnippet
snippet t. "t.date (tcda)"
t.date :${1:title}
t.$0
endsnippet
snippet t. "t.datetime (tcdt)"
t.datetime :${1:title}
t.$0
endsnippet
snippet t. "t.decimal (tcd)"
t.decimal :${1:title}${2:${3:, :precision => ${4:10}}${5:, :scale => ${6:2}}}
t.$0
endsnippet
snippet t. "t.float (tcf)"
t.float :${1:title}
t.$0
endsnippet
snippet t. "t.integer (tci)"
t.integer :${1:title}
t.$0
endsnippet
snippet t. "t.lock_version (tcl)"
t.integer :lock_version, :null => false, :default => 0
t.$0
endsnippet
snippet t. "t.references (tcr)"
t.references :${1:taggable}${2:, :polymorphic => ${3:{ :default => '${4:Photo}' \}}}
t.$0
endsnippet
snippet t. "t.rename (tre)"
t.rename(:${1:old_column_name}, :${2:new_column_name})
t.$0
endsnippet
snippet t. "t.string (tcs)"
t.string :${1:title}
t.$0
endsnippet
snippet t. "t.text (tct)"
t.text :${1:title}
t.$0
endsnippet
snippet t. "t.time (tcti)"
t.time :${1:title}
t.$0
endsnippet
snippet t. "t.timestamp (tcts)"
t.timestamp :${1:title}
t.$0
endsnippet
snippet t. "t.timestamps (tctss)"
t.timestamps
t.$0
endsnippet
snippet vaoif "validates_acceptance_of if"
validates_acceptance_of :${1:terms}${2:${3:, :accept => "${4:1}"}${5:, :message => "${6:You must accept the terms of service}"}}, :if => proc { |obj| ${7:obj.condition?} }}
endsnippet
snippet vao "validates_acceptance_of"
validates_acceptance_of :${1:terms}${2:${3:, :accept => "${4:1}"}${5:, :message => "${6:You must accept the terms of service}"}}
endsnippet
snippet va "validates_associated (va)"
validates_associated :${1:attribute}${2:, :on => :${3:create}}
endsnippet
snippet vaif "validates_associated if (vaif)"
validates_associated :${1:attribute}${2:, :on => :${3:create}, :if => proc { |obj| ${5:obj.condition?} }}
endsnippet
snippet vc "validates_confirmation_of (vc)"
validates_confirmation_of :${1:attribute}${2:, :on => :${3:create}, :message => "${4:should match confirmation}"}
endsnippet
snippet vcif "validates_confirmation_of if (vcif)"
validates_confirmation_of :${1:attribute}${2:, :on => :${3:create}, :message => "${4:should match confirmation}", :if => proc { |obj| ${5:obj.condition?} }}
endsnippet
snippet ve "validates_exclusion_of (ve)"
validates_exclusion_of :${1:attribute}${2:, :in => ${3:%w( ${4:mov avi} )}, :on => :${5:create}, :message => "${6:extension %s is not allowed}"}
endsnippet
snippet veif "validates_exclusion_of if (veif)"
validates_exclusion_of :${1:attribute}${2:, :in => ${3:%w( ${4:mov avi} )}, :on => :${5:create}, :message => "${6:extension %s is not allowed}"}, :if => proc { |obj| ${7:obj.condition?} }}
endsnippet
snippet vfif "validates_format_of if"
validates_format_of :${1:attribute}, :with => /${2:^[${3:\w\d}]+\$}/${4:, :on => :${5:create}, :message => "${6:is invalid}"}, :if => proc { |obj| ${7:obj.condition?} }}
endsnippet
snippet vf "validates_format_of"
validates_format_of :${1:attribute}, :with => /${2:^[${3:\w\d}]+\$}/${4:, :on => :${5:create}, :message => "${6:is invalid}"}
endsnippet
snippet viif "validates_inclusion_of if"
validates_inclusion_of :${1:attribute}${2:, :in => ${3:%w( ${4:mov avi} )}, :on => :${5:create}, :message => "${6:extension %s is not included in the list}"}, :if => proc { |obj| ${7:obj.condition?} }}
endsnippet
snippet vi "validates_inclusion_of"
validates_inclusion_of :${1:attribute}${2:, :in => ${3:%w( ${4:mov avi} )}, :on => :${5:create}, :message => "${6:extension %s is not included in the list}"}
endsnippet
snippet vl "validates_length_of (vl)"
validates_length_of :${1:attribute}, :within => ${2:3..20}${3:, :on => :${4:create}, :message => "${5:must be present}"}
endsnippet
snippet vlif "validates_length_of if"
validates_length_of :${1:attribute}, :within => ${2:3..20}${3:, :on => :${4:create}, :message => "${5:must be present}"}, :if => proc { |obj| ${6:obj.condition?} }}
endsnippet
snippet vnif "validates_numericality_of if"
validates_numericality_of :${1:attribute}${2:, :on => :${3:create}, :message => "${4:is not a number}"}, :if => proc { |obj| ${5:obj.condition?} }}
endsnippet
snippet vn "validates_numericality_of"
validates_numericality_of :${1:attribute}${2:, :on => :${3:create}, :message => "${4:is not a number}"}
endsnippet
snippet vp "validates_presence_of (vp)"
validates_presence_of :${1:attribute}${2:, :on => :${3:create}, :message => "${4:can't be blank}"}
endsnippet
snippet vpif "validates_presence_of if (vpif) 2"
validates_presence_of :${1:attribute}${2:, :on => :${3:create}, :message => "${4:can't be blank}"}, :if => proc { |obj| ${5:obj.condition?} }}
endsnippet
snippet vu "validates_uniqueness_of (vu)"
validates_uniqueness_of :${1:attribute}${2:, :on => :${3:create}, :message => "${4:must be unique}"}
endsnippet
snippet vuif "validates_uniqueness_of if (vuif)"
validates_uniqueness_of :${1:attribute}${2:, :on => :${3:create}, :message => "${4:must be unique}", :if => proc { |obj| ${6:obj.condition?} }}
endsnippet
snippet verify "verify -- render"
verify :only => [:$1], :method => :post, :render => {:status => 500, :text => "use HTTP-POST"}
endsnippet
snippet verify "verify -- redirect"
verify :only => [:$1], :session => :user, :params => :id, :redirect_to => {:action => '${2:index}'}
endsnippet
snippet wants "wants_format"
wants.${1:js|xml|html}${2: { $0 \}}
endsnippet
snippet xdelete "xhr delete"
xhr :delete, :${1:destroy}, :id => ${2:1}$0
endsnippet
snippet xget "xhr get"
xhr :get, :${1:show}${2:, :id => ${3:1}}$0
endsnippet
snippet xpost "xhr post"
xhr :post, :${1:create}, :${2:object} => { $3 }
endsnippet
snippet xput "xhr put"
xhr :put, :${1:update}, :id => ${2:1}, :${3:object} => { $4 }$0
endsnippet
snippet finl "find(:last)"
find(:last${1:, :conditions => ['${2:${3:field} = ?}', ${5:true}]})
endsnippet
snippet sweeper "Create sweeper class"
class ${1:Model}Sweeper < ActionController::Caching::Sweeper
observe ${1:Model}
def after_save(${1/./\l$0/})
expire_cache(${1/./\l$0/})
end
def after_destroy(${1/./\l$0/})
expire_cache(${1/./\l$0/})
end
private
def expire_cache(${1/./\l$0/})
${0:expire_page ${1/./\l$0/}s_path
expire_page ${1/./\l$0/}_path(${1/./\l$0/})}
end
end
endsnippet
snippet col "collection routes"
collection do
${1:get :${2:action}}
${3:put :${4:action}}
${5:post :${6:action}}
${7:delete :${8:action}}
end
endsnippet
snippet format "format (respond_with)"
format.${1:html|xml|json|js|any} { $0 }
endsnippet
snippet gem "gem"
gem '${1:name}'${2:${3:, "${4:1.0}"}${5:${6:, :require => ${7:"${8:$1}"}}${9:, :group => :${10:test}}}}
endsnippet
snippet gemg "gem :git"
gem '${1:paperclip}', :git => "${2:git://github.com/thoughtbot/paperclip.git}"${3:, :branch => "${4:rails3}"}
endsnippet
snippet match "match"
match '${1:${2::controller}${3:/${4::action}${5:/${6::id}${7:(.:format)}}}}'${8: => '${9:$2}#${10:$4}'${11:, :as => :${12:$10}}}
endsnippet
snippet member "member routes"
member do
${1:get :${2:action}}
${3:put :${4:action}}
${5:post :${6:action}}
${7:delete :${8:action}}
end
endsnippet
snippet res "resources"
resources :${1:posts}${2: do
$3
end}
endsnippet
snippet scope "scope"
scope :${1:name}, ${2:joins(:${3:table}).}where(${4:'${5:$3.${6:field}} = ?', ${7:'${8:value}'}})
endsnippet
snippet scopel "scope lambda"
scope :${1:name}, lambda { |${2:param}| ${3:where(${4::${5:field} => ${6:"${7:value}"}})} }
endsnippet
snippet scopee "scope with extension"
scope :${1:name}, ${2:where(${3::${4:field} => ${5:'${6:value}'}})} do
def ${7:method_name}
$0
end
end
endsnippet
snippet sb "scoped_by"
scoped_by_${1:attribute}(${2:id})
endsnippet
snippet setup "setup do..end"
setup do
$0
end
endsnippet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment