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
  • 相关阅读:
    34 bootstrap引入
    32 jQuery——自制飞粒特效
    32 EasyUI——初识、导入至项目
    前端学习相关
    31 jQuery——元素进出场动画效果
    30 jQuery——操作事件
    30 jQuery——操作文档结构
    29 jQuery——操作元素样式
    28 jQuery——操作元素内容
    27 jquery——操作元素属性
  • 原文地址:https://www.cnblogs.com/lmg-jie/p/8761035.html
Copyright © 2011-2022 走看看