Skip to content

Instantly share code, notes, and snippets.

@xdite
Created July 12, 2016 20:25
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 18 You must be signed in to fork a gist
  • Save xdite/fe1da2982e08cc964640a3d88cb4dd65 to your computer and use it in GitHub Desktop.
Save xdite/fe1da2982e08cc964640a3d88cb4dd65 to your computer and use it in GitHub Desktop.
Group CRUD
class GroupsController < ApplicationController
def index
@groups = Group.all
end
def new
@group = Group.new
end
def show
@group = Group.find(params[:id])
end
def edit
@group = Group.find(params[:id])
end
def create
@group = Group.new(group_params)
if @group.save
redirect_to groups_path
else
render :new
end
end
def update
@group = Group.find(params[:id])
if @group.update(group_params)
redirect_to groups_path, notice: 'Update Success'
else
render :edit
end
end
def destroy
@group = Group.find(params[:id])
@group.destroy
redirect_to groups_path, alert: 'Group deleted'
end
private
def group_params
params.require(:group).permit(:title, :description)
end
end
@jkxruby
Copy link

jkxruby commented Jun 7, 2017

def new
@group = Group.new
end
def index
@groups = Group.all
end
def show
@group = Group.find(params[:id)
end
def edit
@group = Group.find(params[:id])
end
def create
@group =Group.new(group_params)
if @group.save
redirect_to groups_path
else
render :new
end
end
def update
@group = Group.find(parmas[:id])
if @group.update(group_parmas)
redirect_to groups_path , notcie"update success"
else
render :edit
end
end

def destroy
@group =Group.find(parmas[:id])
@group.destroy
rendiect_to groups_path, alert: "delete?"
end
end
private
def group_parmas
params.require(:group).permit(:title, :description)
end

@zhu-weijie
Copy link

class GroupsController < ApplicationController
def index
@groups = Group.all
end

def new
@group = Group.new
end

def create
@group = Group.new(group_params)
if @group.save
redirect_to groups_path
else
render :new
end

def show
@group = Group.find(params[:id])
end

def edit
@group = Group.find(params[:id])
end

def update
@group = Group.find(params[:id])
if @group.update(group_params)
redirect_to groups_path, notice: 'You updated the group successfully.'
else
render :edit
end

def destroy
@group = Group.find(params[:id])
@group.destroy
redirect_to groups_path, alert: 'You deleted the group successfully.'
end

private
def group_params
params.require(:group).permit(:title, :description)
end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment