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
  • 相关阅读:
    什么是分布式系统?
    Asp组件中级入门与精通系列之五
    什麼是RIA?
    .NET Remoting编程简介
    WEB打印大全(转)
    ASP与ActiveX控件交互实战(二)
    Asp组件中级入门与精通系列之七
    jswindow对象的方法和属性资料
    什麼是SOAP?
    体验Visual Studio 2005之类设计器
  • 原文地址:https://www.cnblogs.com/lmg-jie/p/8761035.html
Copyright © 2011-2022 走看看