Short Ruby Newsletter

Share this post

Rails 7.1 validate with endless and beginless range

newsletter.shortruby.com
Code Summaries

Rails 7.1 validate with endless and beginless range

#code #summary #rails71 #validation #validators

Lucian Ghinda
Sep 1, 2022
3
Share this post

Rails 7.1 validate with endless and beginless range

newsletter.shortruby.com

This is a summary of the article, and some of the code lines are taken from there:

https://www.bigbinary.com/blog/rails-7-adds-endless-ranges-for-activemodel-validations

# Code Summary for article # https://www.bigbinary.com/blog/rails-7-adds-endless-ranges-for-activemodel-validations  # Works on Rails 7.1  # endless range example class Person   validates_length_of :first_name, in: 20.. end  # endless range example class User   validates_length_of :first_name, within: 20.. end  # endless and beginless range example class Food   validates :created_at, inclusion: { in: proc { (..Date.today) } }   validates :expired_at, inclusion: { in: proc { (Date.today..) } } end
Source: https://www.bigbinary.com/blog/rails-7-adds-endless-ranges-for-activemodel-validations

Code:

# endless range example
class Person
  validates_length_of :first_name, in: 20..
end

# endless range example
class User
  validates_length_of :first_name, within: 20..
end

# endless and beginless range example
class Food
  validates :created_at, inclusion: { in: proc { (..Date.today) } }
  validates :expired_at, inclusion: { in: proc { (Date.today..) } }
end
Share this post

Rails 7.1 validate with endless and beginless range

newsletter.shortruby.com
Previous
Next
Comments
TopNewCommunity

No posts

Ready for more?

© 2023 Lucian Ghinda
Privacy ∙ Terms ∙ Collection notice
Start WritingGet the app
Substack is the home for great writing