Sortable Table 项目技术文档
1. 安装指南
由于该项目已被标记为“DEPRECATED”,Thoughtbot 不再支持此项目。如果您仍然希望使用或维护此项目,请直接联系 Thoughtbot(hello@thoughtbot.com)。
如果您决定继续使用此项目,可以按照以下步骤进行安装:
1.1 安装插件
在您的 Rails 应用中,通过以下命令安装 sortable_table
插件:
script/plugin install git://github.com/thoughtbot/sortable_table.git
1.2 配置控制器和助手
在 app/controllers/application_controller.rb
文件中,添加以下代码以包含 SortableTable
的控制器模块:
class ApplicationController < ActionController::Base
include SortableTable::App::Controllers::ApplicationController
end
在 app/helpers/application_helper.rb
文件中,添加以下代码以包含 SortableTable
的助手模块:
module ApplicationHelper
include SortableTable::App::Helpers::ApplicationHelper
end
2. 项目的使用说明
2.1 控制器配置
在您的控制器中,使用 sortable_attributes
方法定义可排序的属性。例如,在 UsersController
中:
class UsersController < Admin::BaseController
sortable_attributes :name, :email, :age, :group => "groups.name"
def index
@users = User.paginate :page => params[:page], :order => sort_order
end
end
sortable_attributes
方法会定义一个 sort_order
方法,该方法会在控制器的 index
动作中被调用。如果没有提供 params[:sort]
参数,默认会按照 :name
属性进行排序。
2.2 视图配置
在视图中,使用 sortable_table_header
方法创建可排序的表头。例如:
<h1>Users</h1>
<table>
<tr>
<%= sortable_table_header :name => "Name", :sort => "name" %>
<%= sortable_table_header :name => "Email", :sort => "email" %>
<%= sortable_table_header :name => "Age", :sort => "age" %>
<%= sortable_table_header :name => "Group", :sort => "group" %>
</tr>
<% @users.each do |user| %>
<tr>
<td><%= html_escape(user.name) %></td>
<td><%= html_escape(user.email) %></td>
<td><%= html_escape(user.age) %></td>
<td><%= html_escape(user.group.name) %></td>
</tr>
<% end %>
</table>
sortable_table_header
方法会生成一个包含排序链接的表头,并根据排序状态添加 ascending
或 descending
类,以便您可以自定义样式。
3. 项目API使用文档
3.1 sortable_attributes
sortable_attributes
方法用于定义控制器中可排序的属性。它会在控制器中生成一个 sort_order
方法,用于获取当前的排序顺序。
参数:
:name
:属性名称。:group
:关联属性的名称(例如"groups.name"
)。
示例:
sortable_attributes :name, :email, :age, :group => "groups.name"
3.2 sortable_table_header
sortable_table_header
方法用于在视图中生成可排序的表头。它会根据当前的排序状态生成带有排序链接的表头。
参数:
:name
:表头显示的名称。:sort
:对应的排序属性。
示例:
<%= sortable_table_header :name => "Name", :sort => "name" %>
4. 项目安装方式
如前所述,该项目已被标记为“DEPRECATED”,Thoughtbot 不再支持此项目。如果您仍然希望使用此项目,可以通过以下方式安装:
script/plugin install git://github.com/thoughtbot/sortable_table.git
安装后,按照上述的控制器和视图配置进行使用。
注意:由于项目已被弃用,建议您寻找或开发替代方案以满足您的需求。
鸿蒙开发工具大赶集
本仓将收集和展示鸿蒙开发工具,欢迎大家踊跃投稿。通过pr附上您的工具介绍和使用指南,并加上工具对应的链接,通过的工具将会成功上架到我们社区。012hertz
Go 微服务 HTTP 框架,具有高易用性、高性能、高扩展性等特点。Go01每日精选项目
🔥🔥 每日精选已经升级为:【行业动态】,快去首页看看吧,后续都在【首页 - 行业动态】内更新,多条更新哦~🔥🔥 每日推荐行业内最新、增长最快的项目,快速了解行业最新热门项目动态~~029kitex
Go 微服务 RPC 框架,具有高性能、强可扩展的特点。Go00Cangjie-Examples
本仓将收集和展示高质量的仓颉示例代码,欢迎大家投稿,让全世界看到您的妙趣设计,也让更多人通过您的编码理解和喜爱仓颉语言。Cangjie057毕方Talon工具
本工具是一个端到端的工具,用于项目的生成IR并自动进行缺陷检测。Python040PDFMathTranslate
PDF scientific paper translation with preserved formats - 基于 AI 完整保留排版的 PDF 文档全文双语翻译,支持 Google/DeepL/Ollama/OpenAI 等服务,提供 CLI/GUI/DockerPython06mybatis-plus
mybatis 增强工具包,简化 CRUD 操作。 文档 http://baomidou.com 低代码组件库 http://aizuda.comJava03国产编程语言蓝皮书
《国产编程语言蓝皮书》-编委会工作区018- DDeepSeek-R1探索新一代推理模型,DeepSeek-R1系列以大规模强化学习为基础,实现自主推理,表现卓越,推理行为强大且独特。开源共享,助力研究社区深入探索LLM推理能力,推动行业发展。【此简介由AI生成】Python00
热门内容推荐
最新内容推荐
项目优选









