No commit activity in last 3 years
No release in over 3 years
rails sort plugin
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 5.1.4, ~> 5.1
 Project Readme

Gem Version

SortIndexTable

Overview

This Gem is rails plugin that grant a sort function to an index.html.erb generated by scaffold.

Usage

[step1]
Please you add following code to Gemfile.

gem 'sort_index_table', '~> 0.1.0'

[step2]
Please you change an index.html.erb generated by scaffold that like following code.

<th><%= sort_item "#","id" %></th>
<th><%= sort_item "Name","name" %></th>
<th><%= sort_item "Title","title" %></th>
<th><%= sort_item "Result","result" %></th>
<th colspan="3"></th>

[step3]
Please you change index method in controller file generated by scaffold that like following code.

def index
  @scores = order_model("Score",params[:sort],params[:method])
end

That's all. Have a good rails life!!✨

概要

rails アプリのscaffordで生成したindex.html.erbにソート機能を付与します。

使い方

railsプロジェクトのGemfileに以下を記述し、インストールします。

gem 'sort_index_table', '~> 0.1.0'

index.html.erbのテーブルヘッダー部分を
<%= sort_item "表示名","カラム名" %>というように
以下のような形で修正します。

<th><%= sort_item "#","id" %></th>
<th><%= sort_item "Name","name" %></th>
<th><%= sort_item "Title","title" %></th>
<th><%= sort_item "Result","result" %></th>
<th colspan="3"></th>

また、scaffoldで生成したcontrollerのindex部分を
order_model("モデル名",params[:sort],params[:method])
で返却されものを格納するように変更します。

def index
  @scores = order_model("Score",params[:sort],params[:method])
end