⭐️導入リスト⭐️

掲示板のCRUD機能ユーザーのCRUD機能を追加する。

⭐️導入の流れ(掲示板一覧):

admin_boards_controller(管理者用掲示板全体)

class Admin::BoardsController < Admin::BaseController
  before_action :set_board(set_〇〇:コントローラ内に同じ記述内容のアクションがある場合に記載する。), only: %i[edit show update destroy]#特定アクションのみbefore_actionをつける
	#参考文献:<https://pikawaka.com/rails/before_action>
    #一覧画面の表示アクション
    def index
        @q = Board.ransack(params[:q])
        @boards = @q.result(distinct: true).includes(:user).order(created_at: :desc).page(params[:page])
    end    
    
    #一覧表示画面アクション
    def show; end #(set/boatdのアクション)

    def edit; end #(set/boatdのアクション)

    def update
        if @board.update(board_params)
            redirect_to admin_board_path(@board), success: t('defaults.message.updated', item: Board.model_name.human)
        else
            flash.now[:danger] = t('defaults.message.not_updated', item: Board.model_name.human)
            render :edit
        end
    end
    def destroy!
        @board.destroy
        redirect_to admin_boards_path, success: t('defaults.message.deleted', item: Board.model_name.human)
    end
    
    #privateメソッド
    private

    def set_board
      @board = Board.find(params[:id])
    end

    def board_params
      params.require(:board).permit(:title, :body, :board_image, :board_image_cache)
    end
end

admin/_search_form.html.erb

Untitled

admin/index.html.erb

Untitled

admin/_board.html.erb

Untitled

admin/edit.html.erb

Untitled

admin/show.html.erb

Untitled

⭐️導入の流れ(ユーザー一覧):

users/_search_form.html.erb

Untitled

users/index*.html.erb*

Untitled

users/_user*.html.erb*

Untitled

users/edit.html.erb

Untitled

users/show.html.erb

Untitled