Skip to content

Instantly share code, notes, and snippets.

@jwoertink
Created August 19, 2013 01:14
Show Gist options
  • Select an option

  • Save jwoertink/6265011 to your computer and use it in GitHub Desktop.

Select an option

Save jwoertink/6265011 to your computer and use it in GitHub Desktop.
Bundles > Bundle Editor > Show Bundle Editor > Ruby on Rails > Create resources controller class
class ${1:Model}sController < ApplicationController
before_filter :find_${1/./\l$0/}, only: %i(show edit update destroy)
def index
@${1/./\l$0/}s = ${1:Model}.all
end
def show; end
def new
@${1/./\l$0/} = ${1:Model}.new
end
def edit; end
def create
@${1/./\l$0/} = ${1:Model}.new(${1/./\l$0/}_params)
if @${1/./\l$0/}.save
redirect_to(@${1/./\l$0/}, notice: '${1:Model} was successfully created.')
else
render :new
end
end
def update
if @${1/./\l$0/}.update_attributes(${1/./\l$0/}_params)
redirect_to(@${1/./\l$0/}, notice: '${1:Model} was successfully updated.')
else
render :edit
end
end
def destroy
@${1/./\l$0/}.destroy
redirect_to(${1/./\l$0/}s_url)
end
private
def find_${1/./\l$0/}
@${1/./\l$0/} = ${1:Model}.find(params[:id])
end
def ${1/./\l$0/}_params
params.require(:${1/./\l$0/}).permit(:x, :y)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment