Railscasts #228 - 可排序的表列
我正在关注 Ryan Bates 的关于可排序表列的railscast,并且我已经成功获得了一个用于升序和降序排序的列。
我的表比 Railscast 中的更复杂,因为我有来自不同表的列。
# controller
@cars = Car.find(:all).order(sort_column + " " + sort_direction).includes(:manufacturers)
#view
<%= sortable "age" %>
如何为相关表(例如制造商)添加可排序列?
I am following Ryan Bates' railscast on Sortable Table Columns and I have successfully gotten a column to sort ascending and descending.
My table is more complex than in the Railscast because I have columns from different tables.
# controller
@cars = Car.find(:all).order(sort_column + " " + sort_direction).includes(:manufacturers)
#view
<%= sortable "age" %>
How do you add sortable columns for related tables such as manufacturers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有类似的问题。通过以下内容修复了它:
application_controller 中的排序函数应该是这样的:
I had a similar issue. Got it fixed with something like:
The sort function in the application_controller should be something like this: