Friday Night Thoughts

Nicoll Oliver
3 min readMay 1, 2021

Well you guessed it — it’s Friday night and where am I with my Flatiron Project you might ask? Well, let’s see…. NOT DONE. Do I understand what my problem is, YES but do I know how to fix it no.

This Rails project has definitely kicked my butt in more way than I can count but what I did improve at would be chaining together methods with their associations. My best friend has definitely been ‘rails c’ or ‘binding.pry’.

Let’s take a look at my project I’m currently working on: A Perfect Blend. I am making a web app for a local coffee shop that my husband’s family owns. It is merging with a local farmer’s market I personally use to own. Inside this web app will consist of it’s static pages of their menu, about the shop and then it comes to the dynamic pages: Beyond the Blend Market. The goal is to make it an eCommerce site… eventually when completely done.

Figuring out the associations kicked my butt — I have a user model, in which I implemented an enum:

enum :role = [:customer, :vendor, :admin]

This was so helpful and resourceful. Remember enum is index based, meaning customer has a value of : 0, where vendor is 1 and admin is 2. Do what you want with that info but it wasn’t a hard topic to grasp. Play around with it and see what it can do! I had implemented a :vendor column in my table, but it was useless when I figured out how to use enum and the methods it came with. I consistently use:

current_user.costomer? || current_user.vendor? 

These methods would either give me back a truthy or falsey value and would come in handy when dealing with my logic.

Another model I used was Product, Cart, and Cart_Product (join table). See my associations below:

User: 
has_many :products, foreign_key: :vendor_id
has_one :cart
has_many :order_products, through: :cart, source: :products
Product:
has_many :cart_products
has_many :carts, through: :cart_products
has_many :users, through: :carts
Cart:
belongs_to :user
has_many :cart_products
has_many :products, through: :cart_products
Cart_Product:
belongs_to :cart
belongs_to :product
has_one :user, through: :cart

These associations at the end of the day made me learn a lot and helped me be more confident in using the methods to make my life easier. My favorite method was:

f = User.first
f.cart.cart_products
and usingx.errors.full_messages

I am slowly getting more comfortable with playing around with methods and seeing what the outcome of putting things together. Now to finish this project and when I finally feel good about it, we move on to the next section. Wish me luck… I am slowly but surely getting there.

When you get discouraged think where you are now vs where you were at a week ago or when this program started. I have to keep reminding myself that I have never coded before in my life! Do I love it? Yes! It’s definitely challenging at times but the reward at the end, that feeling is such a great thing to feel.

In other news, not about coding — my husband who is supportive of me in this program and has been deployed for about a year will finally be coming home next month! As if single parenting two toddlers isn’t challenging enough?! I teach them somethings, they will even sit in lecture from time to time. So if you need that nudge to join that program if you were hesitating, do it….you might surprise yourself.

--

--