ruby on rails - How do I create a dropdown of the valid values set by validates_inclusion_of? -



ruby on rails - How do I create a dropdown of the valid values set by validates_inclusion_of? -

i have user model object permission attribute restricted validates_inclusion_of ['user','org_admin','site_admin']. when designing create/edit form object, don't want duplicate list, in case changes later. there "rails way" this, or should extract list of valid values attribute accessible outside of instance?

if wanted work strings define user::permissions constance includes mentioned permissions.

class user < activerecord::base permissions = ['user','org_admin','site_admin'] validates_inclusion_of :permission, :in => permissions end

a simplified form (using simple_form in example)

simple_form_for(@user) |f| f.input :permission, :as => :select, :collection => user::permissions end

it neater create permissions model , save permission_id when create new user.

there improve ways i'm looking forwards other answers.

ruby-on-rails forms dry validation

Comments

Popular posts from this blog

java - How to pass parameters between Request-Scoped Controllers? -

actionscript 3 - Flex: moving a point with rotation doesnt change the point XY? -

string - what is the difference between "some" == "some\0" and strcmp("some","some\0") in c++? -