<repo_name>JangWH/jblog<file_sep>/app/controllers/articles_controller.rb
class ArticlesController < ApplicationController
  before_action :set_article, only: %i[show edit update destroy]
  http_basic_authenticate_with name: 'admin', password: '<PASSWORD>!', except: %i[index show search]

  def index
    @articles = Article.all
  end

  def show; end

  def new
    @article = Article.new
  end

  def create
    @article = Article.new(article_params)
    if @article.save
      redirect_to @article, notice: '성공적으로 생성되었습니다!'
    else
      render :new
    end
  end

  def edit; end

  def update
    if @article.update(article_params)
      redirect_to @article, notice: '성공적으로 업데이트되었습니다!'
    else
      render :edit
    end
  end

  def destroy
    redirect_to articles_path, class: '성공적으로 삭제되었습니다!' if @article.destroy
  end

  def search
    @articles = if params[:search].blank?
                  Article.all
                else
                  Article.search(params)
               end
  end

  private

  def set_article
    @article = Article.find(params[:id])
  end

  def article_params
    params.require(:article).permit(:title, :text)
  end
end
<file_sep>/app/helpers/application_helper.rb
module ApplicationHelper
  # if on active page color = white
  # if not on activve page color = regular

  # takes arguments: "link", "what page its on", "url", "change font color"
  def active_link_to(nav_link, contrl, action, url, style)
    if controller_name == contrl && action_name == action
      link_to nav_link, url, id: style
    else
      link_to nav_link, url, class: style
    end
  end

  def korean_country
    %w[서울특별시 대구광역시 인천광역시 광주광역시 대전광역시 울산광역시 세종특별자치시 경기도 충청북도 충청남도 경상북도 경상남도 전라북도 전라남도 제주특별자치도]
  end
end
<file_sep>/app/models/subscriber.rb
class Subscriber < ApplicationRecord
  validates :f_name, presence: true
  validates :l_name, presence: true
  validates :email, presence: true
end
<file_sep>/app/controllers/subscribers_controller.rb
class SubscribersController < ApplicationController
  before_action :set_subscriber, only: [:destroy]
  http_basic_authenticate_with name: 'admin', password: '<PASSWORD>!', except: %i[create]

  def index
    @subscribers = Subscriber.all
  end

  def create
    @subscriber = Subscriber.new(subscriber_params)
    # check if email exists in database table
    if Subscriber.exists?(@subscriber.email)
      redirect_to root_path, alert: '죄송합니다, 그 이메일은 이미 존재합니다!'
    elsif
      @subscriber.save
      redirect_to root_path, notice: '제 뉴스 레터를 구독해 주셔서 감사합니다!'
    else
      redirect_to root_path, alert: '죄송합니다. 정보를 저장하지 못 했습니다. 다시 시도하십시오!'
    end
  end

  def destroy
    redirect_to subscribers_path if @subscriber.destroy
  end

  private

  def set_subscriber
    @subscriber = Subscriber.find(params[:id])
  end

  def subscriber_params
    params.require(:subscriber).permit(:f_name, :l_name, :email, :country)
  end
end
