sift:轻松在Rails控制器中添加过滤

时间:2021-05-05 10:14:06
【文件属性】:
文件名称:sift:轻松在Rails控制器中添加过滤
文件大小:68KB
文件格式:ZIP
更新时间:2021-05-05 10:14:06
Ruby 筛 一个用于构建自己的过滤器并使用Rails和Active Record进行排序的工具! 开发人员使用情况 在您的控制器中包括Sift,并定义一些过滤器。 class PostsController < ApplicationController include Sift filter_on :title , type : :string def index render json : filtrate ( Post . all ) end end 这将允许用户通过?filters[title]=foo并获得Post标题为小号foo 。 Sift还将使用标准的rails errors结构来处理渲染错误。 您可以通过添加以下内容将其添加到您的控制器中: before_action :render_filter_errors , unless : :filte

网友评论