DEV Community

Discussion on: Ruby on Rails .create Rollback Mystery

Collapse
 
racheladaw profile image
Rachel Williams

Thanks for posting El. I've definitely run into that issue with belongs_to before, but I don't usually use the foreign_key attribute. How come this is more syntactically correct?

On a side note, have you looked into using ActiveStorage for images? I'm starting to use it on my final project and its pretty nice. It allows you to easily upload images to cloud services to save space in your db.

Collapse
 
elmarshall profile image
El Marshall (she/they)

Ooh, we should talk some time about the images thing, I'd like to implement some proper image storage for one of my projects.

As for why it's syntactically correct... I'll be honest, it's just what I was told. Didn't question it much, maybe I should have, haha. My guess is that it's more intuitive and clearer. Walking into this code totally fresh, someone can now see, ok, these are foreign keys connecting this to other models. Without that marker, someone unfamiliar with the program would have to do a bit of searching to understand what was up.

Collapse
 
racheladaw profile image
Rachel Williams

Yeah definitely! I mostly followed this blog which is pretty straightforward. I also blogged about the process and how I implemented it in my app.

Ah okay that makes sense. I realize I would be confused too if I hadn't learned about ActiveRecord before reading the code. It definitely makes it more clear.