Very similar to Vense's rails extension and Peng Lv's snippets but with my own twists and added snippets :)
I plan to modify, extend and add more to this over time as I learn more about Ruby and Rails.
- Ruby (.rb)
- Embedded Ruby (html.erb)
- Slim (html.slim)
control/command + space
loads the snippet suggestions if they aren't shown right away.$1
is where the snippet starts.$0
is where the snippet ends.- Press
tab
to move onto the next part of a snippet.
do
$0
end
if $1
$0
end
else
$0
end
if $1
$2
else
$0
end
if $1
$2
elsif $3
$0
end
if $1
$2
elsif
$3
else
$0
end
first(${quantity})
find_by(${1:key}: ${2:value})
find_by(${1:id_name}: params[:${2:param}])
where(${condition})
increment(:${1:id})
order(${1:column}: :${2:desc})
limit(${quantity})
def ${1:name}
$2
end
${1:array}.map { |${2:i}| $0}
${1:array}.select { |${2:i}| $0}
${1:array}.inject(${2:0}) { |{$3:acc}, ${4:i}| $0}
${1:array}.all? {|${2:i}| $0}
${1:array}.any? {|${2:i}| $0}
begin
$1
rescue => exception
$0
end
begin
$1
rescue => exception
$2
ensure
$3
end
begin
$1
rescue => exception
$2
else
$3
end
begin
$1
rescue => exception
$2
else
$3
ensure
$4
end
class ${1:ClassName}
def initialize
$0
end
end
class ${1:ClassName}
def initialize(${2:first})
@${2:first} = ${2:first}
end
$0
end
class ${1:ClassName}
def initialize(${2:first}, ${3:second})
@${2:first} = ${2:first}
@${3:second} = ${3:second}
end
$0
end
class ${1:ClassName}
def initialize(${2:first}, ${3:second}, ${4:third})
@${2:first} = ${2:first}
@${3:second} = ${3:second}
@${4:third} = ${4:third}
end
$0
end
class ${1:ClassName} < ${2:ParentClass}
$0
end
class ${1:ClassName}
$0
end
for ${1:value} in ${2:enumerable} do
$0
end
${1:items}.each do |${2:item}|
$0
end
loop do
$0
end
while ${1:test}
$0
end
until ${1:test}
$0
end
module ${1:ModuleName}
$0
end
unless ${1:test}
$0
end
unless ${1:test}
$2
else
$3
end
namespace :{1} do
desc '$2',
task $3: :environment do
$4
end
end
only: %i[${1:method}]
except: %i[${1:method}]
get '/${1:route}', to: '${2:controller}#${3:method}'
post '/${1:route}', to: '${2:controller}#${3:method}'
patch '/${1:route}', to: '${2:controller}#${3:method}'
put '/${1:route}', to: '${2:controller}#${3:method}'
delete '/${1:route}', to: '${2:controller}#${3:method}'
resources :${res_name}
resources :${1:res_name} do
$2
end
resources :${1:res_name} do
collection do
$2
end
end
resources :${1:res_name} do
member do
$2
end
end
resource :${res_name}
resource :${1:res_name} do
$2
end
resource :${1:res_name} do
collection do
$2
end
end
resource :${1:res_name} do
member do
$2
end
end
member do
$1
end
collection do
$1
end
render $0
redirect_to ${1:path}
redirect_to ${path}, notice: '${msg}'
has_one :$0
dependent: :${1:id}
has_one :${1:id}, dependent: :${2:type}
has_many :$0
has_many :${1:model1}, through: :${2:model2}
has_many :${1:id}, dependent: :${2:type}
belongs_to :
belongs_to :${1:id}, cache: ${2:true}
has_and_belongs_to_many :${1:id}
add_column :${1:table}, :${2:column}, :${3:type}
add_reference :${1:table}, :${2:column}, foreign_key: true
x = binary/boolean/date/datetime/decimal/float/integer/references/string/text/time/timestamp/timestamps
params.require(:${1:id_name}).permit(:${2:variable})
params['$1']['$2']['$3']$0
require '$1'$0
require(:$1)$0
include($1)$0
permit(${1:id});
class ${1:Name}Controller < ApplicationController
$2
end
def index
$1
end
def create
$0
end
def new
$0
end
def edit
$0
end
def show
$0
end
def update
$0
end
def destroy
$0
end
def index
end
def new
end
def create
end
def edit
end
def update
end
def show
end
def destroy
end
before_action :${1:id}
<% $1 %>
<%= $1 %>
<% $1 %>
$0
<% end %>
<%= $1 %>
$0
<% end %>
<% ${1:items}.each do |${2:item}| %>
$0
<% end %>
<%= form_for ${1:variable} do |${2:f}| %>
$0
<% end %>
<%= f.time_zone_select :${1:id_name} %>
<%= range_field (:${1:model_name}, :${2:id_name}, in: ${3:1..100}) %>
<%= select_tag (:${1:id_name}, options_for_select(${2:options}))%>
<%= color_field :${$1:id_name} %>
options_for_select([${1:options}])$0
<%= render ${1:path} %>$0
<%= render ${1:path}, ${2:var1}: ${3:var2} %>
<%= link_to '${1:text}', ${2:path} %>
<%= link_to '${1:text}', ${2:path}, class:'${3:class}' %>
<%= link_to '${1:link_text}', ${2:path}, method: '${3:method}', data:{ ${4:data} } %>
<%= link_to '${1:link_text}', ${2:path}, method: '${3:method}', data:{ ${4:data} }, class:'${5:class}' %>
<%= link_to \"${1:link_text}\", ${2:path}, method: \"${3:method}\", data:{ confirm: \"${4:confirm}\"} %>
<%= link_to \"${1:link_text}\", ${2:path}, method: \"${3:method}\", data:{ confirm: \"${4:confirm}\"}, class:\"${5:class}\" %>
<%= f.submit %>$0
<%= f.label :${1:id_name}, '${2:text}' %>$0
<%= f.number_field (:${1:id_name}, in: ${2:1.0..20.0}, step: ${3:0.5}) %>$0
<%= f.time_field :${1:id_name} %>
[hiddenfield] hidden_field
<%= f.hidden_field :${1:id_name} %>
<%= f.hidden_field :${1:id_name} %>
<%= f.url_field :${id_name} %>
<%= f.password_field :${id_name} %>
<%= f.text_area :${id_name} %>
<%= f.check_box :${id_name} %>
<%= f.text_field :${id_name} %>
<%= f.date_field :${id_name} %>
<%= f.datetime_field :${1:id_name} %>
<%= f.radio_button :${1:name}, :value => '${2:value}' %>
<%= f.input :${1:id}, label: '${2:text}' %>
${1:path}_path
new_${1:path}_path
edit_${1:path}_path(${2:variable})
<% if $1 %>
$2
<% end %>
<% else %>
<% elsif $1 %>$0
<% if $1 %>
$2
<% else %>
$3
<% end %>
<% if $1 %>
$2
<% elseif %>
$3
<% end %>
<% if $1 %>
$2
<% elseif %>
$3
<% else %>
$4
<% end %>
<% unless ${1:falsevalue} %>
$2
<% end %>
<% unless ${1:falsevalue} %>
$2
<% else %>
$3
<% end %>
<% end %>
# frozen_string_literal_true
- Add
gem 'prettier'
to your gemfile - Run
bundle
in your terminal - Optionally create a
.prettierrc
file for configuration in the root of your project directory. here's a link to the repo for rb prettier - Copy and paste this snippet into your terminal
bundle exec rbprettier --write '**/*.rb'
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa
- Copy and paste these two lines into your terminal
- Push to your repository without entering your password