Comments (3)
Ok, I see that is already implemented in #50333
from rails.
validate: ...
is an implemented syntax, not a _validate: ...
. Why do you expect it to work?
from rails.
validate: ...
is an implemented syntax, not a_validate: ...
. Why do you expect it to work?
Hi,
This is just how enums are built.
You can do the following:
enum :my_enum, [:value, :value2], prefix: true, suffix: false, instance_methods: false, validate: true
enum another_enum2: { value: "something" }, _prefix: true, _suffix: false, _instance_methods: false
But in the second instance you can't do the following: _validate: true
It simply appears to have been forgotten, don't you agree?
By looking at the implementation, it seems we can declare many enums at once:
enum enum1: { value: "something" }, enum2: { hello: "world" }, _prefix: true
So because _validate: true
isn't explicitly in the slice!(...)
ActiveRecord thinks it's another enum to define.
Edit: To those interested, this initializer fix the behavior in the mean time
module ValidatableEnum
extend ActiveSupport::Concern
included do
def self.enum(name = nil, values = nil, **options)
return super if name
definitions = options.slice!(:_prefix, :_suffix, :_scopes, :_default, :_instance_methods, :_validate)
options.transform_keys! { |key| :"#{key[1..]}" }
definitions.each { |name, values| _enum(name, values, **options) }
end
end
end
ActiveSupport.on_load(:active_record) { include ValidatableEnum }
from rails.
Related Issues (20)
- ActiveRecord.upset generates a databases warning with MySQL 8
- ActionText::RichText attachments not cleaned up when content made empty HOT 1
- add a better interface to the issues tab on this repo HOT 1
- Unnecessary auto save is triggered for polymorphic has_one defined in child class using single-table inheritance HOT 5
- ActiveStorage ProxyController sets Cache-Control headers on errors like FileNotFoundError HOT 3
- Using preload with composite keys can cause too many records to be read HOT 3
- Empty multipart form data raises ActionController::BadRequest error since Rails 7.0.5 HOT 9
- Incompatible with nio4r 2.5.8 gem when running Bundle Install (Rails version 7.0.5.1) HOT 2
- Can't use Model.exists? with composite primary keys HOT 1
- Missing Active Record encryption credential when using ActiveRecord::Encryption.without_encryption HOT 3
- Forked child processes created through rails runner throw error from ActiveRecord when exiting HOT 3
- Add .default method to ActiveSupport::ParameterFilter (syntax sugar) HOT 2
- RedisCacheStore not fault tolerant (as I expected) HOT 3
- Doc have typo? HOT 3
- `ActiveRecord::Migration::check_all_pending!` resets connection pool when in use in other threads HOT 2
- migrate `migrate` folder to `migrations` HOT 3
- Using a secret_key_base from `secrets.yml` should raise a deprecation warning in development HOT 1
- Autoloaded classes raise NameError when accessed in parent's on_load hook during load HOT 6
- Active Storage bug HOT 3
- [Question]`mark_for_destruction` not destroying records when loading using `find_by` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rails.