This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Demonstration of why you should use Faker's .unique option when using | |
# Faker on attributes with uniqueness constraints | |
def first_collision_lazy | |
names={} | |
1_000.times do |a| | |
name = Faker::Company.name | |
return names.count if names[name] | |
names[name]=true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Widget < ActiveRecord::Base | |
## add data_class option when calling attr_encrypted | |
attr_encrypted :written_on, key: MY_SECURE_KEY, marshal: true, data_class: Date | |
end | |
## This monkeypatch of ActiveRecord ensures that Rails knows that `written_on` is a date when setting it via | |
## forms/assign_attributes. | |
## | |
## The problem: | |
## When submitted via form, the `written_on` attribute is submitted in parts, with these params: |