2023-10-25 20:25:29 +00:00
|
|
|
class Admin::LanguagesController < ApplicationController
|
2023-10-25 03:47:01 +00:00
|
|
|
|
|
|
|
def index
|
|
|
|
@languages = Language.all
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@language = Language.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@language = Language.new(language_params)
|
|
|
|
if @language.save
|
|
|
|
flash[:notice] = "Language successfully created."
|
2023-10-25 20:25:29 +00:00
|
|
|
redirect_to admin_languages_path
|
2023-10-25 03:47:01 +00:00
|
|
|
else
|
|
|
|
render :new, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@language = Language.find_by_id(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@language = Language.find_by_id(params[:id])
|
|
|
|
if @language.update(language_params)
|
|
|
|
flash[:notice] = "Language successfully updated."
|
2023-10-25 20:25:29 +00:00
|
|
|
redirect_to admin_languages_path
|
2023-10-25 03:47:01 +00:00
|
|
|
else
|
|
|
|
render :edit, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@language = Language.find_by_id(params[:id])
|
|
|
|
if @language.destroy
|
|
|
|
flash[:notice] = "Language successfully deleted."
|
2023-10-25 20:25:29 +00:00
|
|
|
redirect_to admin_languages_path
|
2023-10-25 03:47:01 +00:00
|
|
|
else
|
|
|
|
render :index, status: :not_modified
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def language_params
|
|
|
|
params.require(:language).permit(:name)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|