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

Restricting the names of named groups #40

Open
mrmod opened this issue Feb 21, 2016 · 1 comment
Open

Restricting the names of named groups #40

mrmod opened this issue Feb 21, 2016 · 1 comment
Labels

Comments

@mrmod
Copy link

mrmod commented Feb 21, 2016

I love this gem btw. Thanks for making it! I'm up and running and was wondering:

  • How can I restrict/control the name of a named group?

I'd thought about

class GroupMembership < Groupify::ActiveRecord::NamedGroupCollection
  validates_format_of :group_name, with: /\AWingedLoraxOfThe(North|South|East|West)/Z/
end

To make sure my Lorax's are only the winged variety of the cardinal directions. Would this be the best-practice or is there perhaps something inside the docs I've missed for doing the same thing?

@dwbutler
Copy link
Owner

Hi,

There is no configuration option to support that currently. Your sample code looks like it will work for your use case. (Note that GroupMembership should inherit from ActiveRecord::Base.)

The problem with this strategy in general is that different classes can also have named group memberships, and you might want to have different validation rules (or none) for those classes.

I'll think about ways to incorporate validation.

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

No branches or pull requests

2 participants