How to use enums in Ruby on Rails
Web-Crunch
Ruby on Rail's ships with a module known as Enum which has a parent class of ActiveRecord. This handy module allows you to declare different states in the database using any Model in your Rails application.
Enums are powerful thanks to the built-in methods and scopes that come with the framework. So rather than rolling all your methods in a given model, you can use a convention-based approach to manipulate a given state of something in an app.
In this guide I'll walk you through how to use Enums as well as all of the options Ruby on Rails provides.
Source code: https://github.com/justalever/enum_guide
Hi, My name is Andy Leverenz and I work as a product designer and developer. For fun, I design, code, and write. Check out my blog called Web-Crunch https://web-crunch.com where I publish design and development tutorials with the occasional vlog.
♥️ Sponsor me on GitHub https://github.com/sponsors/justalever
☕️ Keep me awake. Buy me a coffee https://www.buymeacoffee.com/webcrunch
📰 One-Click Subscribe: https://www.youtube.com/user/webcrunchblog?sub_confirmation=1
💻 Previously published at: https://web-crunch.com/posts/how-to-use-enums-ruby-on-rails
💎Ruby on Rails Course: HELLO RAILS https://hellorails.io
💻 Check out the blog: https://web-crunch.com
🦄 Check out my personal site: https://justalever.com
🚀 Links: Weekly Newsletter: https://digest.web-crunch.com/ Twitter: https://twitter.com/webcrunchblog Github: https://github.com/justalever
📘Check out my book on UX Design: "LUXD: Learn User Experience Design" https://web-crunch.com/products/luxd
📙 Check out my FREE book on Tumblr Theming: "Pro Tumblr Theming" https://web-crunch.com/products/ptt ... https://www.youtube.com/watch?v=EiceC-m2UmI
62078378 Bytes