class MaterialsController < ApplicationController

  def index
    @materials = Material.page(params[:page]).per(20)
  end

  def new
    @material = Material.new
  end

  def create
    @material = Material.new(material_site_params)
    if @material.save
      redirect_to @material
    else
      render 'edit'
    end
  end

  def show
    @material = Material.find(params[:id])
  end

  def edit
    @material = Material.find(params[:id])
  end

  def update
    @material = Material.find(params[:id])
    if @material.update(material_site_params)
      redirect_to @material
    else
      render 'edit'
    end
  end

  def destroy
    @material = Material.find(params[:id])
    @material.destroy
    redirect_to materials_path
  end

  private
  def material_site_params
    params.require(:material).permit(:name, :unit, :owner)
  end
end
