1
0
Fork 0
mirror of synced 2024-11-23 17:25:35 -05:00
ultimate-vim/sources_non_forked/vim-snippets/UltiSnips/rails.snippets

879 lines
21 KiB
Text
Raw Normal View History

priority -50
2012-08-16 23:41:25 -04:00
snippet anaf "accepts_nested_attributes_for"
2019-03-08 06:04:56 -05:00
accepts_nested_attributes_for :${1:association_name}${2:${3:, allow_destroy: true}${4:, reject_if: proc \{ |obj| ${5:obj.blank?} \}}}
2012-08-16 23:41:25 -04:00
endsnippet
snippet tcbi "Create binary column"
2019-03-08 06:04:56 -05:00
t.binary :${1:title}${2:, limit: ${3:2}.megabytes}
2012-08-16 23:41:25 -04:00
$0
endsnippet
snippet tcb "Create boolean column"
t.boolean :${1:title}
$0
endsnippet
2016-02-20 08:13:10 -05:00
snippet clac "Create controller class"
2012-08-16 23:41:25 -04:00
class ${1:Model}Controller < ApplicationController
2019-03-08 06:04:56 -05:00
before_action :find_${2:model}
2012-08-16 23:41:25 -04:00
$0
private
2017-02-11 08:01:38 -05:00
def find_$2
2012-08-16 23:41:25 -04:00
@$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"
2019-03-08 06:04:56 -05:00
t.decimal :${1:title}${2:${3:, precision: ${4:10}}${5:, scale: ${6:2}}}
2012-08-16 23:41:25 -04:00
$0
endsnippet
snippet tcf "Create float column"
t.float :${1:title}
$0
endsnippet
2016-02-20 08:13:10 -05:00
snippet clact "Create functional test class"
2012-08-16 23:41:25 -04:00
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"
2019-03-08 06:04:56 -05:00
t.integer :lock_version, null: false, default: 0
2012-08-16 23:41:25 -04:00
$0
endsnippet
# FIXME: handling literal bracket pair inside of nested tab groups?
snippet tcr "Create references column"
2019-11-30 07:06:56 -05:00
t.references :${1:taggable}${2:, polymorphic: ${3:{ default: '${4:Photo}' }}}
2012-08-16 23:41:25 -04:00
$0
endsnippet
snippet resources "Create resources controller class"
class ${1:Model}sController < ApplicationController
2019-03-08 06:04:56 -05:00
before_action :find_${1/./\l$0/}, only: [:show, :edit, :update, :destroy]
# GET /${1/./\l$0/}s
2019-03-08 06:04:56 -05:00
# GET /${1/./\l$0/}s.json
def index
@${1/./\l$0/}s = ${1:Model}.all
respond_to do |wants|
wants.html # index.html.erb
2019-03-08 06:04:56 -05:00
wants.json { render json: @${1/./\l$0/}s }
end
end
# GET /${1/./\l$0/}s/1
2019-03-08 06:04:56 -05:00
# GET /${1/./\l$0/}s/1.json
def show
respond_to do |wants|
wants.html # show.html.erb
2019-03-08 06:04:56 -05:00
wants.json { render json: @${1/./\l$0/} }
end
end
# GET /${1/./\l$0/}s/new
2019-03-08 06:04:56 -05:00
# GET /${1/./\l$0/}s/new.json
def new
@${1/./\l$0/} = ${1:Model}.new
respond_to do |wants|
wants.html # new.html.erb
2019-03-08 06:04:56 -05:00
wants.json { render json: @${1/./\l$0/} }
end
end
# GET /${1/./\l$0/}s/1/edit
def edit
end
# POST /${1/./\l$0/}s
2019-03-08 06:04:56 -05:00
# POST /${1/./\l$0/}s.json
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/}) }
2019-03-08 06:04:56 -05:00
wants.json { render json: @${1/./\l$0/}, status: :created, location: @${1/./\l$0/} }
else
2019-03-08 06:04:56 -05:00
wants.html { render action: "new" }
wants.json { render json: @${1/./\l$0/}.errors, status: :unprocessable_entity }
end
end
end
# PUT /${1/./\l$0/}s/1
2019-03-08 06:04:56 -05:00
# PUT /${1/./\l$0/}s/1.json
def update
respond_to do |wants|
2016-02-20 08:13:10 -05:00
if @${1/./\l$0/}.update(params[:${1/./\l$0/}])
flash[:notice] = '${1:Model} was successfully updated.'
wants.html { redirect_to(@${1/./\l$0/}) }
2019-03-08 06:04:56 -05:00
wants.json { head :ok }
else
2019-03-08 06:04:56 -05:00
wants.html { render action: "edit" }
wants.json { render json: @${1/./\l$0/}.errors, status: :unprocessable_entity }
end
end
end
# DELETE /${1/./\l$0/}s/1
2019-03-08 06:04:56 -05:00
# DELETE /${1/./\l$0/}s/1.json
def destroy
@${1/./\l$0/}.destroy
respond_to do |wants|
wants.html { redirect_to(${1/./\l$0/}s_url) }
2019-03-08 06:04:56 -05:00
wants.json { head :ok }
end
end
private
def find_${1/./\l$0/}
@${1/./\l$0/} = ${1:Model}.find(params[:id])
end
2012-08-16 23:41:25 -04:00
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)"
2019-03-08 06:04:56 -05:00
assert_redirected_to ${2:action: "${1:index}"}
2012-08-16 23:41:25 -04:00
endsnippet
snippet asre "Test Assert Response (are)"
assert_response :${1:success}, @response.body$0
endsnippet
snippet aftc "after_create"
after_create $0
2012-08-16 23:41:25 -04:00
endsnippet
snippet aftd "after_destroy"
after_destroy $0
2012-08-16 23:41:25 -04:00
endsnippet
snippet afts "after_save"
after_save $0
2012-08-16 23:41:25 -04:00
endsnippet
snippet aftu "after_update"
after_update $0
2012-08-16 23:41:25 -04:00
endsnippet
snippet aftv "after_validation"
after_validation $0
2012-08-16 23:41:25 -04:00
endsnippet
snippet aftvoc "after_validation_on_create"
after_validation_on_create $0
2012-08-16 23:41:25 -04:00
endsnippet
snippet aftvou "after_validation_on_update"
after_validation_on_update $0
2012-08-16 23:41:25 -04:00
endsnippet
snippet asg "assert(var = assigns(:var))"
2017-02-11 08:01:38 -05:00
assert(${1:var} = assigns(:$1), "Cannot find @$1")
2012-08-16 23:41:25 -04:00
$0
endsnippet
snippet asd "assert_difference"
assert_difference "${1:Model}.${2:count}", ${3:1} do
$0
2012-08-16 23:41:25 -04:00
end
endsnippet
snippet asnd "assert_no_difference"
assert_no_difference "${1:Model}.${2:count}" do
$0
2012-08-16 23:41:25 -04:00
end
endsnippet
snippet artnpp "assert_redirected_to (nested path plural)"
2017-02-11 08:01:38 -05:00
assert_redirected_to ${10:${2:parent}_${3:child}_path(${4:@}${5:$2})}
2012-08-16 23:41:25 -04:00
endsnippet
snippet artnp "assert_redirected_to (nested path)"
2017-02-11 08:01:38 -05:00
assert_redirected_to ${2:${12:parent}_${13:child}_path(${14:@}${15:$12}, ${16:@}${17:$13})}
2012-08-16 23:41:25 -04:00
endsnippet
snippet artpp "assert_redirected_to (path plural)"
assert_redirected_to ${10:${2:model}s_path}
endsnippet
snippet artp "assert_redirected_to (path)"
2017-02-11 08:01:38 -05:00
assert_redirected_to ${2:${12:model}_path(${13:@}${14:$12})}
2012-08-16 23:41:25 -04:00
endsnippet
snippet asrj "assert_rjs"
assert_rjs :${1:replace}, ${2:"${3:dom id}"}
endsnippet
snippet ass "assert_select"
2019-03-08 06:04:56 -05:00
assert_select '${1:path}'${2:, ${3:text}: ${4:'${5:inner_html}'}}${6: do
2012-08-16 23:41:25 -04:00
$0
end}
endsnippet
snippet befc "before_create"
before_create $0
2012-08-16 23:41:25 -04:00
endsnippet
snippet befd "before_destroy"
before_destroy $0
2012-08-16 23:41:25 -04:00
endsnippet
snippet befs "before_save"
before_save $0
2012-08-16 23:41:25 -04:00
endsnippet
snippet befu "before_update"
before_update $0
2012-08-16 23:41:25 -04:00
endsnippet
snippet befv "before_validation"
before_validation $0
2012-08-16 23:41:25 -04:00
endsnippet
snippet befvoc "before_validation_on_create"
before_validation_on_create $0
2012-08-16 23:41:25 -04:00
endsnippet
snippet befvou "before_validation_on_update"
before_validation_on_update
endsnippet
snippet bt "belongs_to (bt)"
2019-03-08 06:04:56 -05:00
belongs_to :${1:object}${2:, class_name: "${3:${1/[[:alpha:]]+|(_)/(?1::\u$0)/g}}", foreign_key: "${4:$1_id}"}
2012-08-16 23:41:25 -04:00
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) }
2019-03-08 06:04:56 -05:00
wants.json { render json: @$1, status: :created, location: @$1 }
2012-08-16 23:41:25 -04:00
else
2019-03-08 06:04:56 -05:00
wants.html { render action: "new" }
wants.json { render json: @$1.errors, status: :unprocessable_entity }
2012-08-16 23:41:25 -04:00
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})
2019-03-08 06:04:56 -05:00
}get :$1${6:, id: @$3.to_param}
2012-08-16 23:41:25 -04:00
assert_response :success
$0
end
endsnippet
snippet deftp "def post request"
def test_should_post_${1:action}
${3:@$2 = ${4:$2s}(:${5:fixture_name})
2019-03-08 06:04:56 -05:00
}post :$1${6:, id: @$2.to_param}, ${2:model}: { $0 }
2012-08-16 23:41:25 -04:00
assert_response :redirect
end
endsnippet
snippet fina "find(:all)"
2019-03-08 06:04:56 -05:00
find(:all${1:, conditions: ['${2:${3:field} = ?}', ${5:true}]})
2012-08-16 23:41:25 -04:00
endsnippet
snippet finf "find(:first)"
2019-03-08 06:04:56 -05:00
find(:first${1:, conditions: ['${2:${3:field} = ?}', ${5:true}]})
2012-08-16 23:41:25 -04:00
endsnippet
snippet fini "find(id)"
find(${1:id})
endsnippet
snippet fine "find_each"
2019-03-08 06:04:56 -05:00
find_each(${1conditions: {:${2:field}: ${3:true}\}}) do |${4:${TM_CURRENT_WORD/(\w+)\./\L$1/g}}|
2012-08-16 23:41:25 -04:00
$0
end
endsnippet
snippet finb "find_in_batches"
2019-03-08 06:04:56 -05:00
find_in_batches(${1conditions: {:${2:field}: ${3:true}\}}) do |${4:${TM_CURRENT_WORD/(\w+)\./\L$1/g}}s|
2012-08-16 23:41:25 -04:00
$4s.each do |$4|
$0
end
end
endsnippet
snippet habtm "has_and_belongs_to_many (habtm)"
2019-03-08 06:04:56 -05:00
has_and_belongs_to_many :${1:object}${2:, join_table: "${3:table_name}", foreign_key: "${4:$1_id}"}
2012-08-16 23:41:25 -04:00
endsnippet
snippet hm "has_many (hm)"
2019-03-08 06:04:56 -05:00
has_many :${1:object}s${2:, class_name: "$1", foreign_key: "${4:reference}_id"}
2012-08-16 23:41:25 -04:00
endsnippet
snippet hmt "has_many (through)"
2019-03-08 06:04:56 -05:00
has_many :${1:objects}, through: :${2:join_association}${3:, source: :${4:$2_table_foreign_key_to_$1_table}}
2012-08-16 23:41:25 -04:00
endsnippet
2019-03-08 06:04:56 -05:00
snippet hmd "has_many dependent: :destroy"
has_many :${1:object}s${2:, class_name: "$1", foreign_key: "${4:reference}_id"}, dependent: :destroy$0
2012-08-16 23:41:25 -04:00
endsnippet
snippet ho "has_one (ho)"
2019-03-08 06:04:56 -05:00
has_one :${1:object}${2:, class_name: "${3:${1/[[:alpha:]]+|(_)/(?1::\u$0)/g}}", foreign_key: "${4:$1_id}"}
2012-08-16 23:41:25 -04:00
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"
2019-03-08 06:04:56 -05:00
${1:map}.catch_all "*${2:anything}", controller: "${3:default}", action: "${4:error}"
2012-08-16 23:41:25 -04:00
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
2012-08-16 23:41:25 -04:00
end}
endsnippet
snippet maprs "map.resources"
${1:map}.resources :${2:resource}${10: do |${11:$2}|
$0
2012-08-16 23:41:25 -04:00
end}
endsnippet
snippet mapwo "map.with_options"
2019-03-08 06:04:56 -05:00
${1map}.with_options :${2:controller}: '${3:thing}' do |${4:$3}|
2012-08-16 23:41:25 -04:00
$0
end
endsnippet
snippet mrw "mattr_accessor"
mattr_accessor :${0:attr_names}
endsnippet
snippet ncl "named_scope lambda"
2019-03-08 06:04:56 -05:00
named_scope :name, lambda { |${1param}| { :conditions: ${3:['${4:${5:field} = ?}', ${6:$1}]} } }
2012-08-16 23:41:25 -04:00
endsnippet
snippet nc "named_scope"
2019-03-08 06:04:56 -05:00
named_scope :name${1:, joins: :${2:table}}, conditions: ${3:['${4:${5:field} = ?}', ${6:true}]}
2012-08-16 23:41:25 -04:00
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)"
2019-03-08 06:04:56 -05:00
redirect_to action: "${1:index}"
2012-08-16 23:41:25 -04:00
endsnippet
snippet reai "redirect_to (action, id)"
2019-03-08 06:04:56 -05:00
redirect_to action: "${1:show}", id: ${0:@item}
2012-08-16 23:41:25 -04:00
endsnippet
snippet rec "redirect_to (controller)"
2019-03-08 06:04:56 -05:00
redirect_to controller: "${1:items}"
2012-08-16 23:41:25 -04:00
endsnippet
snippet reca "redirect_to (controller, action)"
2019-03-08 06:04:56 -05:00
redirect_to controller: "${1:items}", action: "${2:list}"
2012-08-16 23:41:25 -04:00
endsnippet
snippet recai "redirect_to (controller, action, id)"
2019-03-08 06:04:56 -05:00
redirect_to controller: "${1:items}", action: "${2:show}", id: ${0:@item}
2012-08-16 23:41:25 -04:00
endsnippet
snippet renpp "redirect_to (nested path plural)"
2017-02-11 08:01:38 -05:00
redirect_to(${2:${10:parent}_${11:child}_path(${12:@}${13:$10})})
2012-08-16 23:41:25 -04:00
endsnippet
snippet renp "redirect_to (nested path)"
2017-02-11 08:01:38 -05:00
redirect_to(${2:${12:parent}_${13:child}_path(${14:@}${15:$12}, ${16:@}${17:$13})})
2012-08-16 23:41:25 -04:00
endsnippet
snippet repp "redirect_to (path plural)"
redirect_to(${2:${10:model}s_path})
endsnippet
snippet rep "redirect_to (path)"
2017-02-11 08:01:38 -05:00
redirect_to(${2:${12:model}_path(${13:@}${14:$12})})
2012-08-16 23:41:25 -04:00
endsnippet
snippet reb "redirect_to :back"
redirect_to :back
endsnippet
snippet ra "render (action)... (ra)"
2019-03-08 06:04:56 -05:00
render action: "${1:action}"
2012-08-16 23:41:25 -04:00
endsnippet
snippet ral "render (action,layout) (ral)"
2019-03-08 06:04:56 -05:00
render action: "${1:action}", layout: "${2:layoutname}"
2012-08-16 23:41:25 -04:00
endsnippet
snippet rf "render (file) (rf)"
2019-03-08 06:04:56 -05:00
render file: "${1:filepath}"
2012-08-16 23:41:25 -04:00
endsnippet
snippet rfu "render (file,use_full_path) (rfu)"
2019-03-08 06:04:56 -05:00
render file: "${1:filepath}", use_full_path: ${2:false}
2012-08-16 23:41:25 -04:00
endsnippet
snippet ri "render (inline) (ri)"
2019-03-08 06:04:56 -05:00
render inline: "${1:<%= 'hello' %>}"
2012-08-16 23:41:25 -04:00
endsnippet
snippet ril "render (inline,locals) (ril)"
2019-03-08 06:04:56 -05:00
render inline: "${1:<%= 'hello' %>}", locals { ${2::name}: "${3:value}"$4 }
2012-08-16 23:41:25 -04:00
endsnippet
snippet rit "render (inline,type) (rit)"
2019-03-08 06:04:56 -05:00
render inline: "${1:<%= 'hello' %>}", type: ${2::rjson}
2012-08-16 23:41:25 -04:00
endsnippet
snippet rl "render (layout) (rl)"
2019-03-08 06:04:56 -05:00
render layout: "${1:layoutname}"
2012-08-16 23:41:25 -04:00
endsnippet
snippet rn "render (nothing) (rn)"
2019-03-08 06:04:56 -05:00
render nothing: ${1:true}
2012-08-16 23:41:25 -04:00
endsnippet
snippet rns "render (nothing,status) (rns)"
2019-03-08 06:04:56 -05:00
render nothing: ${1:true}, status: ${2:401}
2012-08-16 23:41:25 -04:00
endsnippet
snippet rt "render (text) (rt)"
2019-03-08 06:04:56 -05:00
render text: "${1:text to render...}"
2012-08-16 23:41:25 -04:00
endsnippet
snippet rtl "render (text,layout) (rtl)"
2019-03-08 06:04:56 -05:00
render text: "${1:text to render...}", layout: "${2:layoutname}"
2012-08-16 23:41:25 -04:00
endsnippet
snippet rtlt "render (text,layout => true) (rtlt)"
2019-03-08 06:04:56 -05:00
render text: "${1:text to render...}", layout: ${2:true}
2012-08-16 23:41:25 -04:00
endsnippet
snippet rts "render (text,status) (rts)"
2019-03-08 06:04:56 -05:00
render text: "${1:text to render...}", status: ${2:401}
2012-08-16 23:41:25 -04:00
endsnippet
snippet ru "render (update)"
render :update do |${2:page}|
$2.$0
end
endsnippet
snippet rest "respond_to"
respond_to do |wants|
2019-11-30 07:06:56 -05:00
wants.${1:html}${2: { $0 }}
2012-08-16 23:41:25 -04:00
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
2018-02-04 06:35:08 -05:00
endsnippet
snippet cmm "Create Migration Model Class"
class Migration${1/(?:^|_)(\w)/\u$1/g} < ApplicationRecord
self.table_name = :${1:model_name}s
end
2012-08-16 23:41:25 -04:00
endsnippet
snippet t. "t.binary (tcbi)"
2019-03-08 06:04:56 -05:00
t.binary :${1:title}${2:, limit: ${3:2}.megabytes}
2012-08-16 23:41:25 -04:00
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)"
2019-03-08 06:04:56 -05:00
t.decimal :${1:title}${2:${3:, precision: ${4:10}}${5:, scale: ${6:2}}}
2012-08-16 23:41:25 -04:00
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)"
2019-03-08 06:04:56 -05:00
t.integer :lock_version, null: false, default: 0
2012-08-16 23:41:25 -04:00
t.$0
endsnippet
snippet t. "t.references (tcr)"
2019-11-30 07:06:56 -05:00
t.references :${1:taggable}${2:, polymorphic: ${3:{ default: '${4:Photo}' }}}
2012-08-16 23:41:25 -04:00
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"
2019-03-08 06:04:56 -05:00
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?} }}
2012-08-16 23:41:25 -04:00
endsnippet
snippet vao "validates_acceptance_of"
2019-03-08 06:04:56 -05:00
validates :${1:terms}${2:, acceptance: ${3:{ accept: "${4:1}"${5:, message: "${6:You must accept the terms of service}"}}} }
2012-08-16 23:41:25 -04:00
endsnippet
snippet va "validates_associated (va)"
2019-03-08 06:04:56 -05:00
validates_associated :${1:attribute}${2:, on: :${3:create}}
2012-08-16 23:41:25 -04:00
endsnippet
snippet vaif "validates_associated if (vaif)"
2019-03-08 06:04:56 -05:00
validates_associated :${1:attribute}${2:, on: :${3:create}, if: proc { |obj| ${5:obj.condition?} }}
2012-08-16 23:41:25 -04:00
endsnippet
snippet vc "validates_confirmation_of (vc)"
2019-03-08 06:04:56 -05:00
validates_confirmation_of :${1:attribute}${2:, on: :${3:create}, message: "${4:should match confirmation}"}
2012-08-16 23:41:25 -04:00
endsnippet
snippet vcif "validates_confirmation_of if (vcif)"
2019-03-08 06:04:56 -05:00
validates_confirmation_of :${1:attribute}${2:, on: :${3:create}, message: "${4:should match confirmation}", if: proc { |obj| ${5:obj.condition?} }}
2012-08-16 23:41:25 -04:00
endsnippet
snippet ve "validates_exclusion_of (ve)"
2019-03-08 06:04:56 -05:00
validates_exclusion_of :${1:attribute}${2:, in: ${3:%w( ${4:mov avi} )}, on: :${5:create}, message: "${6:extension %s is not allowed}"}
2012-08-16 23:41:25 -04:00
endsnippet
snippet veif "validates_exclusion_of if (veif)"
2019-03-08 06:04:56 -05:00
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?} }}
2012-08-16 23:41:25 -04:00
endsnippet
snippet vfif "validates_format_of if"
2019-03-08 06:04:56 -05:00
validates_format_of :${1:attribute}, with: /${2:^[${3:\w\d}]+\$}/${4:, on: :${5:create}, message: "${6:is invalid}"}, if: proc { |obj| ${7:obj.condition?} }}
2012-08-16 23:41:25 -04:00
endsnippet
snippet vf "validates_format_of"
2019-03-08 06:04:56 -05:00
validates_format_of :${1:attribute}, with: /${2:^[${3:\w\d}]+\$}/${4:, on: :${5:create}, message: "${6:is invalid}"}
2012-08-16 23:41:25 -04:00
endsnippet
snippet viif "validates_inclusion_of if"
2019-03-08 06:04:56 -05:00
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?} }}
2012-08-16 23:41:25 -04:00
endsnippet
snippet vi "validates_inclusion_of"
2019-03-08 06:04:56 -05:00
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}"}
2012-08-16 23:41:25 -04:00
endsnippet
snippet vl "validates_length_of (vl)"
2019-03-08 06:04:56 -05:00
validates_length_of :${1:attribute}, within: ${2:3..20}${3:, on: :${4:create}, message: "${5:must be present}"}
2012-08-16 23:41:25 -04:00
endsnippet
snippet vlif "validates_length_of if"
2019-03-08 06:04:56 -05:00
validates_length_of :${1:attribute}, within: ${2:3..20}${3:, on: :${4:create}, message: "${5:must be present}"}, if: proc { |obj| ${6:obj.condition?} }}
2012-08-16 23:41:25 -04:00
endsnippet
snippet vnif "validates_numericality_of if"
2019-03-08 06:04:56 -05:00
validates_numericality_of :${1:attribute}${2:, on: :${3:create}, message: "${4:is not a number}"}, if: proc { |obj| ${5:obj.condition?} }}
2012-08-16 23:41:25 -04:00
endsnippet
snippet vn "validates_numericality_of"
2019-03-08 06:04:56 -05:00
validates_numericality_of :${1:attribute}${2:, on: :${3:create}, message: "${4:is not a number}"}
2012-08-16 23:41:25 -04:00
endsnippet
snippet vp "validates_presence_of (vp)"
2019-03-08 06:04:56 -05:00
validates_presence_of :${1:attribute}${2:, on: :${3:create}, message: "${4:can't be blank}"}
2012-08-16 23:41:25 -04:00
endsnippet
snippet vpif "validates_presence_of if (vpif) 2"
2019-03-08 06:04:56 -05:00
validates_presence_of :${1:attribute}${2:, on: :${3:create}, message: "${4:can't be blank}"}, if: proc { |obj| ${5:obj.condition?} }}
2012-08-16 23:41:25 -04:00
endsnippet
snippet vu "validates_uniqueness_of (vu)"
2019-03-08 06:04:56 -05:00
validates_uniqueness_of :${1:attribute}${2:, on: :${3:create}, message: "${4:must be unique}"}
2012-08-16 23:41:25 -04:00
endsnippet
snippet vuif "validates_uniqueness_of if (vuif)"
2019-03-08 06:04:56 -05:00
validates_uniqueness_of :${1:attribute}${2:, on: :${3:create}, message: "${4:must be unique}", if: proc { |obj| ${6:obj.condition?} }}
2012-08-16 23:41:25 -04:00
endsnippet
snippet verify "verify -- render"
2019-03-08 06:04:56 -05:00
verify only: [:$1], method: :post, render {:status: 500, text: "use HTTP-POST"}
2012-08-16 23:41:25 -04:00
endsnippet
snippet verify "verify -- redirect"
2019-03-08 06:04:56 -05:00
verify only: [:$1], session: :user, params: :id, redirect_to {:action: '${2:index}'}
2012-08-16 23:41:25 -04:00
endsnippet
snippet wants "wants_format"
2019-11-30 07:06:56 -05:00
wants.${1:js|json|html}${2: { $0 }}
2012-08-16 23:41:25 -04:00
endsnippet
snippet xdelete "xhr delete"
2019-03-08 06:04:56 -05:00
xhr :delete, :${1:destroy}, id: ${2:1}$0
2012-08-16 23:41:25 -04:00
endsnippet
snippet xget "xhr get"
2019-03-08 06:04:56 -05:00
xhr :get, :${1:show}${2:, id: ${3:1}}$0
2012-08-16 23:41:25 -04:00
endsnippet
snippet xpost "xhr post"
2019-03-08 06:04:56 -05:00
xhr :post, :${1:create}, ${2:object}: { $3 }
2012-08-16 23:41:25 -04:00
endsnippet
snippet xput "xhr put"
2019-03-08 06:04:56 -05:00
xhr :put, :${1:update}, id: ${2:1}, ${3:object}: { $4 }$0
2012-08-16 23:41:25 -04:00
endsnippet
snippet col "collection routes"
collection do
${1:get :${2:action}}
${3:put :${4:action}}
${5:post :${6:action}}
${7:delete :${8:action}}
2012-08-16 23:41:25 -04:00
end
endsnippet
snippet format "format (respond_with)"
format.${1:html|xml|json|js|any} { $0 }
endsnippet
snippet gem "gem"
2019-03-08 06:04:56 -05:00
gem '${1:name}'${2:${3:, "${4:1.0}"}${5:${6:, require: ${7:"${8:$1}"}}${9:, group: :${10:test}}}}
2012-08-16 23:41:25 -04:00
endsnippet
snippet gemg "gem :git"
2019-03-08 06:04:56 -05:00
gem '${1:paperclip}', git: "${2:git://github.com/thoughtbot/paperclip.git}"${3:, branch: "${4:rails3}"}
2012-08-16 23:41:25 -04:00
endsnippet
snippet match "match"
2019-03-08 06:04:56 -05:00
match '${1:${2::controller}${3:/${4::action}${5:/${6::id}${7:(.:format)}}}}'${8: '${9:$2}#${10:$4}'${11:, as: :${12:$10}}}
2012-08-16 23:41:25 -04:00
endsnippet
snippet member "member routes"
member do
${1:get :${2:action}}
${3:put :${4:action}}
${5:post :${6:action}}
${7:delete :${8:action}}
2012-08-16 23:41:25 -04:00
end
endsnippet
snippet res "resources"
resources :${1:posts}${2: do
$3
2012-08-16 23:41:25 -04:00
end}
endsnippet
snippet scope "scope"
2019-03-08 06:04:56 -05:00
scope :${1:name}, { ${2:joins(:${3:table}).}where(${4:'${5:$3.${6:field}} = ?', ${7:'${8:value}'}}) }
2012-08-16 23:41:25 -04:00
endsnippet
snippet scopel "scope lambda"
2019-03-08 06:04:56 -05:00
scope :${1:name}, lambda { |${2:param}| ${3:where(${4::${5:field}: ${6:"${7:value}"}})} }
2012-08-16 23:41:25 -04:00
endsnippet
snippet scopee "scope with extension"
2019-03-08 06:04:56 -05:00
scope :${1:name}, { ${2:where(${3::${4:field}: ${5:'${6:value}'}})} } do
def ${7:method_name}
$0
end
2012-08-16 23:41:25 -04:00
end
endsnippet
snippet sb "scoped_by"
scoped_by_${1:attribute}(${2:id})
endsnippet
snippet setup "setup do..end"
setup do
$0
end
endsnippet
snippet trans "Translation snippet"
2019-03-08 06:04:56 -05:00
I18n.t('`!v substitute(substitute(substitute(@%, substitute(getcwd() . "/", "\/", "\\\\/", "g"), "", ""), "\\(\\.\\(html\\|js\\)\\.\\(haml\\|erb\\)\\|\\(_controller\\)\\?\\.rb\\)$", "", ""), "/", ".", "g")`.${2:${1/[^\w]/_/g}}$3', default: "${1:some_text}"$4)${5:$0}
2012-08-16 23:41:25 -04:00
endsnippet
snippet route_spec
it 'routes to #${1:action}' do
2017-02-11 08:01:38 -05:00
${2:get}('/${3:url}').should route_to('`!v substitute(expand('%:t:r'), '_routing_spec$', '', '')`#$1'${4:, ${5:params}})$6
2012-08-16 23:41:25 -04:00
end
endsnippet
# vim:ft=snippets: