# app/models/post.rb
class Post < ApplicationRecord
scope :filter1, -> { where(status: :filter1) }
scope :filter2, -> { where(status: :filter2) }
scope :filter3, -> { where(status: :filter3) }
scope :recent, -> { order(updated_at: :desc) }
end
# app/controllers/post_controller.rb
class PostsController < ApplicationController
def index
@users = Post.send(params[:filter]).recent
end
end
GET /posts?filter=exit! # => 服务器会被迫停止。
GET /posts?filter_delete_all! # => 删除数据库表的内容会被清除。