bookstore/app/controllers/authors_controller.rb

30 lines
528 B
Ruby
Raw Permalink Normal View History

2021-03-22 03:16:29 +01:00
# frozen_string_literal: true
# Authors controller
2021-03-21 20:30:25 +01:00
class AuthorsController < ApplicationController
2021-03-21 22:31:58 +01:00
before_action :ensure_admin
2021-03-22 03:16:29 +01:00
before_action :set_author, only: %i[edit update]
2021-03-21 22:31:58 +01:00
2021-03-21 20:30:25 +01:00
def index
@authors = Author.all
end
2021-03-21 22:31:58 +01:00
def edit
@author = Author.find(params[:id])
end
def update
2021-03-22 03:16:29 +01:00
redirect_to '/authors' if @author.update(author_params)
2021-03-21 22:31:58 +01:00
end
private
def set_author
@author = Author.find(params[:id])
end
def author_params
params.require(:author).permit(:first_name, :last_name)
end
2021-03-21 20:30:25 +01:00
end