If there are multiple descriptions using the same option, Things that can bring them together. The advantage is that the amount of description can be reduced.
Example: Suppose there are multiple codes in the app / models / item.rb file that use the same options below.
validates :category_id, numericality: { other_than: 1 }
validates :days_to_send_id, numericality: { other_than: 1 }
validates :item_condition_id, numericality: { other_than: 1 }
validates :prace_id, numericality: { other_than: 1 }
validates :fee_id, numericality: { other_than: 1 }
At this time, if you use with_option, you can make the code easy to read with a small amount of description as shown below.
with_option numericality: { other_than:1} do
validates :category_id
validates :days_to_send
validates :item_condition_id
validates :prace_id
validates :fee_id
end
That's it.
Recommended Posts