Created
March 31, 2017 03:07
-
-
Save wilbert/f106081ea8ea1a626bf972798217dfcb to your computer and use it in GitHub Desktop.
Generic Ruby Controller Actions Snippet - Atom
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'.source.ruby': | |
'Index Action': | |
'prefix': 'cai' | |
'body': """ | |
def index | |
@$1 = $2.all | |
respond_with @$1 | |
end | |
""" | |
'Edit Action': | |
'prefix': 'cae' | |
'body': """ | |
def edit | |
@$1 = $2.find(params[:id]) | |
respond_with @$1 | |
end | |
""" | |
'New Action': | |
'prefix': 'can' | |
'body': """ | |
def new | |
@$1 = $2.new | |
respond_with @$1 | |
end | |
""" | |
'Show Action': | |
'prefix': 'cas' | |
'body': """ | |
def show | |
@$1 = $2.find(params[:id]) | |
respond_with @$1 | |
end | |
""" | |
'Create Action': | |
'prefix': 'cac' | |
'body': """ | |
def create | |
@$1 = $2.new($1_params) | |
if @$1.save | |
redirect_to @$1, notice: I18n.t(:created, model: :$1) | |
else | |
render :new | |
end | |
end | |
""" | |
'Update Action': | |
'prefix': 'cau' | |
'body': """ | |
def update | |
@$1 = $2.find(params[:id]) | |
if @$1.update($1_params) | |
redirect_to @$1, notice: I18n.t(:updated, model: :$1) | |
else | |
render :edit | |
end | |
end | |
""" | |
'Delete Action': | |
'prefix': 'cad' | |
'body': """ | |
def destroy | |
@$1 = $2.find(params[:id]) | |
@$1.destroy | |
redirect_to $1s_path, notice: I18n.t(:removed, model: :$1) | |
end | |
""" | |
'New and Create Action': | |
'prefix': 'canc' | |
'body': """ | |
def new | |
@$1 = $2.new | |
respond_with @$1 | |
end | |
def create | |
@$1 = $2.new($1_params) | |
if @$1.save | |
redirect_to @$1, notice: I18n.t(:created, model: :$1) | |
else | |
render :new | |
end | |
end | |
""" | |
'Edit and Update Action': | |
'prefix': 'caeu' | |
'body': """ | |
def edit | |
@$1 = $2.find(params[:id]) | |
respond_with @$1 | |
end | |
def update | |
@$1 = $2.find(params[:id]) | |
if @$1.update($1_params) | |
redirect_to @$1, notice: I18n.t(:updated, model: :$1) | |
else | |
render :edit | |
end | |
end | |
""" | |
'CRUD Action': | |
'prefix': 'crud' | |
'body': """ | |
def index | |
@$1s = $2.all | |
respond_with @$1s | |
end | |
def show | |
@$1 = $2.find(params[:id]) | |
respond_with @$1 | |
end | |
def new | |
@$1 = $2.new | |
respond_with @$1 | |
end | |
def create | |
@$1 = $2.new($1_params) | |
if @$1.save | |
redirect_to @$1, notice: I18n.t(:created, model: :$1) | |
else | |
render :new | |
end | |
end | |
def edit | |
@$1 = $2.find(params[:id]) | |
respond_with @$1 | |
end | |
def update | |
@$1 = $2.find(params[:id]) | |
if @$1.update($1_params) | |
redirect_to @$1, notice: I18n.t(:updated, model: :$1) | |
else | |
render :edit | |
end | |
end | |
def destroy | |
@$1 = $2.find(params[:id]) | |
@$1.destroy | |
redirect_to $1s_path, notice: I18n.t(:removed, model: :$1) | |
end | |
private | |
def $1_params | |
params.require(:$1).permit! | |
end | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment