Created
July 15, 2011 12:58
-
-
Save lucascaton/1084628 to your computer and use it in GitHub Desktop.
Snippet pra Vim - gerar controller com actions RESTful
This file contains 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
class ${1:ModelClassName}sController < ApplicationController | |
def index | |
@${2:model_class_name} = $1.all | |
end | |
def show | |
@$2 = $1.find params[:id] | |
end | |
def new | |
@$2 = $1.new | |
end | |
def create | |
@$2 = $1.new params[:$2] | |
if @$2.save | |
flash[:notice] = '$1 criado(a) com sucesso.' | |
redirect_to @$2 | |
else | |
render :action => 'new' | |
end | |
end | |
def edit | |
@$2 = $1.find params[:id] | |
end | |
def update | |
@$2 = $1.find params[:id] | |
if @$2.update_attributes params[:$2] | |
flash[:notice] = '$1 atualizado(a) com sucesso.' | |
redirect_to @$2 | |
else | |
render :action => 'edit' | |
end | |
end | |
def destroy | |
@$2 = $1.find params[:id] | |
@$2.destroy | |
redirect_to $2s_url | |
end | |
end${3} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment