Hi, I want to allow a user the ability to set certain values for validations via a table called settings. For example a model called loan can have a principal of between 2 values. In the settings table i have a field called max_loan_value and min_loan_value which i would like to be used for validating the amount entered for a loan calculation. validates_inclusion_of :princiapl, :in=>setting.min_value..setting.max_value,:message => ": Loans between £100 and £12320 only" Can anyone let me know if this is possible and point me in the right direction, ive looked about but cant seemt o find what i am looking for. JB -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
John Butler wrote:> I want to allow a user the ability to set certain values for validations > via a table called settings. For example a model called loan can have a > principal of between 2 values. In the settings table i have a field > called max_loan_value and min_loan_value which i would like to be used > for validating the amount entered for a loan calculation. > > validates_inclusion_of :princiapl, > :in=>setting.min_value..setting.max_value,:message => ": Loans between > £100 and £12320 only" > > Can anyone let me know if this is possible and point me in the right > direction, ive looked about but cant seemt o find what i am looking for.One way would be def validate unless (setting.min_value..setting.max_value) === princiapl errors.add(:princiapl, '': Loans between £100 and £12320 only'') end end -- We develop, watch us RoR, in numbers too big to ignore. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks, exactly what i was looking for. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---