Skip to content

Instantly share code, notes, and snippets.

@rafaelrpbelo
Created February 3, 2015 14:25
Show Gist options
  • Save rafaelrpbelo/92f5548f6e485400edd5 to your computer and use it in GitHub Desktop.
Save rafaelrpbelo/92f5548f6e485400edd5 to your computer and use it in GitHub Desktop.
gcrud
<snippet>
<content><![CDATA[
class ${1:model_pluralize}Controller < ApplicationController
before_action :set_${2:model_downcase}, only: [ :show, :edit, :update ]
def index
@${3:model_downcase_pluralize} = ${2:model_downcase}_base.page(params[:p])
end
def new
@${2:model_downcase} = ${4:model}.new
end
def create
@${2:model_downcase} = ${4:model}.create(${2:model_downcase}_params)
respond_with @${2:model_downcase}
end
def show
end
def edit
end
def update
@${2:model_downcase}.update(${2:model_downcase}_params)
respond_with @${2:model_downcase}
end
private
def ${2:model_downcase}_base
apply_scopes(${4:model})
end
def set_${2:model_downcase}
@${2:model_downcase} = ${4:model}.find(params[:id])
end
def ${2:model_downcase}_params
params.require(:${2:model_downcase}).permit(${5:attributes})
end
end
]]></content>
<tabTrigger>g:crud</tabTrigger>
<scope>source.ruby</scope>
</snippet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment