-
-
Save xdite/fe1da2982e08cc964640a3d88cb4dd65 to your computer and use it in GitHub Desktop.
Group CRUD
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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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