Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added some features to sortable_columns #1

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

aldavidson
Copy link

Hi,

Thanks for sortable_columns, it's really handy. If you're interested, I've added a couple of features in my fork:

  1. ability to sort by a model's instance methods, as well as attributes

This is really useful when you're sorting a collection of models by some attribute on an associated record (e.g. to sort @payments by payment.account.name, you'd define :

class Payment < ActiveRecord::Base
belongs_to :account

sortable_methods [:account_name, :some_other_method]

def account_name
self.account.name
end
end

( I added the sortable_methods requirement to avoid a security hole - e.g. sort_by=destroy)

  1. when you're on a url with non-sort parameters (e.g. /things/index?parent_id=1234 ) it now maintains existing params when you click on a sortable column header

  2. As a result of the other two changes, I centralized the logic for validating sort params into one place rather than two

Cheers,

Al

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant