
Security News
Nx npm Packages Compromised in Supply Chain Attack Weaponizing AI CLI Tools
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
SortThis provides a way to sort.
The controller/view code is based off of railscasts episode 228 - Sortable Table Columns.
Here is an example app that demonstrates the usage.
Add this line to your application's Gemfile:
gem 'sort_this'
And then execute:
$ bundle
Add a call to the sortable
method with a hash of sorts
class YourModel < ActiveRecord::Base
sort_this :sort_name => {:column_name => :name, :default => 'ASC', :table_name => 'some_other_table_name', :joins => :association, :clause => "some.clause"}
end
The options are
sort_name: Is the name of the sort, this in most cases will be the same as the column_name, but can be anything
Sort Options:
column_name: (Optional) The name of the column to sort on. If left blank it will use the sort name.
default: (Optional) Defines a default sort if provided. The valid options are 'ASC' or 'DESC'.
table_name: (Optional) Overrides the table name used, should usually be used in coordination with joins.
joins: (Optional) Defines an association to join on, this should be provided if the column is in another table. ** Requires table name to be set. **
This is what you would usually pass into a joins or includes clause for ActiveRecord.
clause: (Optional) Overrides the clause used for the sort.
Then to sort
YourModel.sort("sort_name", "asc|desc|ASC|DESC") => sorted list of YourModel objects
In you controller define a default sort
class SomeController < ApplicationController
sortable "sort_name"
def index
SomeModel.sort(sort_column, sort_direction)
end
end
sortable(sort_name, title = nil, html_options = {})
<%= sortable("sort_name") %>
or custom title
<%= sortable("sort_name", "Sort Different Name") %>
Defined Highest to Lowest priority
Options on the sortable
controller options
Being able to define multiple column sorts
Something like:
sort_this :some_crazy_sort => {
[
{:column_name => :some_column, other options},
...
]
}
not sure how that'd be called though...
Throw error when the table_name option is not set and joins is set.
Define a default scope and remove from the sort method, gives more control to developer.
Define scopes for each sort defined (individual sort scopes)
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that sort_this demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.