yonbergman / enumify Goto Github PK
View Code? Open in Web Editor NEWEnumify adds an enum command to all ActiveRecord models which enables you to work with string attributes as if they were enums
License: MIT License
Enumify adds an enum command to all ActiveRecord models which enables you to work with string attributes as if they were enums
License: MIT License
If I have an enum with :allow_nil => true
, then it can be read from the db as nil, but I cannot set the field to nil using update or simple assignment (=).
If I try to do that I get: NoMethodError: undefined method
to_sym' for nil:NilClass`
after upgrading to rails 4 i prefer to keep using enumify. how would you do that?
The reason is because Rails 4's enum are based on integers and persist the ordinal number of the enum value, unlike enumify which persists the string value. so its a hassle to update the models.
class Partners::Contact < ActiveRecord::Base
enum :status, [:pending, :active]
end
rails s
$ h.contacts.first.status
NoMethodError: undefined method empty?' for 1:Fixnum from /Users/volte/a2/vendor/bundle/gems/enumify-0.0.5/lib/enumify/model.rb:11:in
block in enum'
from (irb):6
This gem is exactly what I've been looking for. Sorry to post this in issues, but heck if I can find a better place to ask questions.
What's the best way to get the index of the value in an enumify field? In my projects, I frequently do things like:
if status_index > 2; something; end
where status_index is the value index according to a mysql query on the enum field
select status+0 status_index from orders...
I also do things like
self.status = 2
save
What about ActiveRecord queries with an enumify field in the :conditions?
:conditions=>{:status=>"submitted"}
or
:conditions=>"orders.status > 2"
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.