Shannon Cochran

RC Week 4: Making progress on Ruby App

Current state of my ruby-wordle-type Rails app:

React weirdness

Using react for the front end and one little nitpick about react- I don’t love the name useEffect and generally don’t find the lifecylce hooks to be clear. In Vue.js the lifecycle hooks were so much more clear to me - things like beforeMount - you can assume whatever happens in that code happens before the component mounts. This made today difficult as I was trying to figure out at what point everything was happening and it wasn’t really clear to me - I didn’t realize things are stored in state asynchronously. I did not expect that to be the case. But maybe I’ll get used to it, there’s got to be a reason React won over more users, right?

Rails and enums

Came across an interesting tidbit about enums and rails - honestly, I didn’t even know what enums were until about a year ago because I never saw them in the database I worked in - now I realize why that might have been the case. Now I don’t feel so bad for not knowing. As I was redo-ing some stuff in my database- specifically creating an enum to store types for the type of input and output of test cases, I looked up how to create an enum in a rails migration and found something like this:

create_table :conversations do |t|
  t.column :status, :integer, default: 0
end

Then I was wondering why the enum was being stored as an int - and apparently this dates back to earlier decisions about how to handle enums for the framework, where the db will store it as an int but ActiveRecord (Rail’s ORM) will pull it out as a string. This was super confusing and made me not want to use an enum but I came across this article https://testdouble.com/insights/optimized-rails-enums-with-postgres about the whole thing which mentioned a gem I can include to get around the whole thing and just use enums straight up in my migration, like so:

create_enum :mood, %w(happy great been_better)

create_table :person do
  t.enum :person_mood, enum_type: :mood
end

This project is like, way more work than I thought and I still have a lot that I want to change but in its current state, its sort of working!