Forum: Ruby on Rails Varaible Validations

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0de83fd56f1af530034ba8efa5490b1b?d=identicon&s=25 John Butler (johnnybutler7)
on 2007-08-01 15:02
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
C64e63b70be7dfed8b0742540b8b27e5?d=identicon&s=25 Mark Reginald James (Guest)
on 2007-08-01 19:01
(Received via mailing list)
John Butler wrote:

> 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.
0de83fd56f1af530034ba8efa5490b1b?d=identicon&s=25 John Butler (johnnybutler7)
on 2007-08-02 15:11
Thanks, exactly what i was looking for.
This topic is locked and can not be replied to.