zoukankan      html  css  js  c++  java
  • 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
    
    
  • 相关阅读:
    面试笔试
    scala(9) Monad
    scala (8) 模糊匹配
    scala (7) Set and Tuple
    scala (6) Map
    scala (5) 可变序列和不可变序列
    scala (4) 可变数组和不可变数组
    scala (3) Function 和 Method
    scala (2) while 和变量
    scala (1) for 循环
  • 原文地址:https://www.cnblogs.com/dccmmtop/p/7356417.html
Copyright © 2011-2022 走看看