bookstore/app/controllers/authors_controller.rb
2021-03-22 03:16:29 +01:00

29 lines
528 B
Ruby

# frozen_string_literal: true
# Authors controller
class AuthorsController < ApplicationController
before_action :ensure_admin
before_action :set_author, only: %i[edit update]
def index
@authors = Author.all
end
def edit
@author = Author.find(params[:id])
end
def update
redirect_to '/authors' if @author.update(author_params)
end
private
def set_author
@author = Author.find(params[:id])
end
def author_params
params.require(:author).permit(:first_name, :last_name)
end
end