Skip to content

Instantly share code, notes, and snippets.

@GiancarlosIO
Last active July 28, 2016 03:58
Show Gist options
  • Save GiancarlosIO/92023518e171e640e4c40a5a6b38bbf8 to your computer and use it in GitHub Desktop.
Save GiancarlosIO/92023518e171e640e4c40a5a6b38bbf8 to your computer and use it in GitHub Desktop.
class UsersController < ApplicationController
before_action :find_course, only: [:show, :edit, :update, :destroy]
def index
@users = User.all
end
def show
# find_user
end
def new
@user = User.new
end
def create
@user = User.new(parameters)
if @user.save
redirect_to user_path(@user), notice: 'Se ha creado el usuario.'
else
render :new
end
end
def edit
# find_user
end
def update
if @user.update(parameters)
redirect_to user_path(@yser), notice: 'Se actualizó el usuario.'
else
render :edit
end
end
def destroy
# find_user
redirect_to action: :index, alert: 'Se elimino el usuer' if @user.destroy
end
private
def parameters
params.require(:user).permit(:name, :last_name, :email)
end
def find_user
if User.find_by(id: params[:id])
@course = User.find(params[:id])
else
redirect_to users_path, alert: "No se encontró el usuario"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment