• before_action使用示例


    module Admin
      class InvitesController < Admin::ApplicationController
      # 调用 show edit update destroy 方法前调用set_invite 方法
        before_action :set_invite, only: [:show, :edit, :update, :destroy]
      
        def index
          @invites = Invite.order('id desc')
          @invites = @invites.paginate(page: params[:page], per_page: 30)
        end
      
        def show
          @subscriptions = @invite.subscriptions.paginate(page: params[:page], per_page: 30)
        end
      
        def new
          @invites = Invite.new
        end
      
        def edit
        end
      
        def create
          @invites = Invite.new(params[:admin_invites_path].permit!)
          if @invite.save
            redirect_to(admin_invites_url, notice: '创建成功。')
          else
            render action: "new"
          end
        end
      
        def update
          if @invite.update_attributes(params[:invite].permit!)
            redirect_to(admin_invites_url, notice: '更新成功。')
          else
            render action: "edit"
          end
        end
      
        def destroy
          @invite.destroy
          redirect_to(admin_invites_url, notice: "删除成功。")
        end
      
        private
      
        def set_invite
          @invite = Invite.find(params[:id])
        end
      end
    
    end
    
    
  • 相关阅读:
    数据的追踪审计
    通知模块设计
    数据库'tempdb' 的事务日志已满处理方法
    三级联动
    组合查询
    用户控件
    MDI容器
    控件说明
    winfrom
    自动生成编号
  • 原文地址:https://www.cnblogs.com/dccmmtop/p/7356417.html
Copyright © 2020-2023  润新知