[LRUG] How to do a db backed enum... or what should I be using...
Chris Kimpton
chris at kimptoc.net
Wed Sep 7 09:52:26 PDT 2011
Hi Riccardo,
Thanks - that seems to work -
https://github.com/kimptoc/scope-enum-tester--using-enumerated_attribute
Regards,
Chris
On 7 September 2011 09:57, Riccardo Tacconi <rtacconi at gmail.com> wrote:
> Hi,
>
> I use a gem file.
>
> In your gemfile add:
>
> gem 'enumerated_attribute'
>
> In your model:
>
> enum_attr :doc_type, %w(diploma teacher_reference student_reference
> course_outline)
>
> Otherwise you can use (in your model) something like this:
>
> ROLES = %w[admin manager user].freeze
>
> def role_in_list
> errors.add(:base, "Role #{self.role} is not allowed") unless
> User::ROLES.include?(self.role)
> end
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20110907/35a5628f/attachment.html>
More information about the Chat
mailing list