zoukankan      html  css  js  c++  java
  • ruby----controller中简单的增删改 方法定义

    class WorkProsController < ApplicationController
      before_action :set_work, only: [:show, :edit, :update, :destroy]
    
      def index
      end
    
      #从set_user 获取数据
      def show
      end
    
      # GET /users/1/edit
      def edit
      end
    
    
      def new
        @work=DWorkPro.new
      end
    
      #成功跳转到show页面
      def create
        @work = DWorkPro.new(work_params)
        respond_to do |format|
          if @work.save
            format.json {render json: {status: 'success', location: @work}}
            format.html {redirect_to work_pro_path(@work), notice: 'Successfully create!'}
          else
            format.json {render json: {status: 'false', location: @work.errors}}
            format.html {render :new}
          end
        end
      end
    
    
      #删除后调转到首页  /work_pros
      def destroy
        respond_to do |format|
          if @work.destroy
            format.html {redirect_to work_pros_path, notice: 'Successfully destroy!'}
            format.json {render json: {status: 'success'}}
          else
            format.json {render json: {status: 'false'}}
          end
        end
      end
    
    
      #成功跳转到show页面
      # PATCH/PUT /work_pros/1
      def update
        respond_to do |format|
          if @work.update(work_params)
            format.json {render json: {status: 'success', location: @work}}
            format.html {redirect_to work_pro_path(@work), notice: 'Succesfully updated!'}
          else
            format.json {render json: {status: 'false', location: @work.errors}}
            format.html {render :edit}
          end
        end
    
      end
    
      private
      def set_work
        @work = DWorkPro.find(params[:id])
      end
    
      def work_params
        params.require(:d_work_pro).permit(:id, :work_name, :work_code, :work_type, :work_flag)
      end
    
    end
  • 相关阅读:
    克如斯卡尔 P1546
    真正的spfa
    第四课 最小生成树 要点
    关于vscode中nullptr未定义
    cmake学习笔记
    python学习笔记
    (BFS 图的遍历) 2906. kotori和迷宫
    (图论基础题) leetcode 997. Find the Town Judge
    (BFS DFS 并查集) leetcode 547. Friend Circles
    (BFS DFS 图的遍历) leetcode 841. Keys and Rooms
  • 原文地址:https://www.cnblogs.com/lmg-jie/p/8761035.html
Copyright © 2011-2022 走看看