You can use the option allow_blank: true
to skip the validation when the attribute is blank/empty/nil.
https://guides.rubyonrails.org/active_record_validations.html#allow-blank
Related Contents:
- Validate uniqueness of multiple columns
- Ruby on Rails Callback, what is difference between :before_save and :before_create?
- Rails 3: “field-with-errors” wrapper changes the page appearance. How to avoid this?
- Rails – Validate Presence Of Association?
- validation custom message for rails 3
- What is the order of ActiveRecord callbacks and validations?
- Controlling the order of rails validations
- Rails DB Migration – How To Drop a Table?
- Add a CSS class to
- Repairing Postgresql after upgrading to OSX 10.7 Lion
- do..end vs curly braces for blocks in Ruby
- How to add 10 days to current time in Rails
- Rails: How to change the text on the submit button in a Rails Form
- How to delete migration files in Rails 3
- Check if record exists from controller in Rails
- How do I prepare test database(s) for Rails rspec tests without running rake spec?
- How to check if a number is included in a range (in one statement)?
- How to run rails s -p80 on 80 port?
- Setting Devise Login to be root page
- before_filter with parameters
- How to get a single column’s values into an array
- how to safely replace all whitespaces with underscores with ruby?
- Where to put Ruby helper methods for Rails controllers?
- Parsing string to add to URL-encoded URL
- Alias for column names in Rails
- Why is my custom rake task in lib/tasks not discovered in Rails 3?
- How to display a Rails flash notice upon redirect?
- Rails 3 / Form without Model: How do I create a form that is not tied to a model?
- Ruby syntax: break out from ‘each.. do..’ block
- Find the newest record in Rails 3
- Rails order by results count of has_many association
- Role does not exist and unable to create database when using PostgreSQL
- Rails naming convention for join table
- rails, simple_form, how to set selected index of a collection when page loaded?
- Why does false invalidate validates_presence_of?
- How to tell which format a controller has resolved to render
- Sending mail with Rails 3 in development environment
- How to update a single attribute without touching the updated_at attribute?
- Rails – Mail, getting the body as Plain Text
- rails get app root/base url
- Rails: Per-environment initializers?
- association named not found perhaps misspelled issue in rails association
- Shortcut for plucking two attributes from an ActiveRecord object?
- Filter to execute before render but after controller?
- redirect to index rather than show after save
- How would you create a notification system like on SO or Facebook in RoR?
- How to validate the date such that it is after today in Rails?
- Iterating between two DateTimes, with a one hour step
- How can I detect if my code is running in the console in Rails 3?
- Rails 3 SSL routing redirects from https to http