Rails: The Struggle Is Real
Tags: rant, webframework, clojure, rails
Published: 2018-10-15 17:21:15

---
title: Rails: The Struggle Is Real
published: true
description: A short rant about rails because to this day, I still don’t get it
tags: rant, web framework, clojure, ruby on rails
---

![](https://thepracticaldev.s3.amazonaws.com/i/0rrawr2rjzh2j16018hi.jpeg)

I don’t know how many hours I’ve lost to searching for what should be the easiest thing but instead I wind up scratching my head because I’m forced to do it a crazy complicated way because some danish dude thought it was a good idea. Don’t get it twisted yo, rails has some positive things going for it, but making sense to *me* is not one of them. Let me give you some concrete examples of some WTF moments I’ve dealt with repeatedly.


## Custom form builder helpers
This is when you want to wrap up a few elements into something nice and neat like

```ruby
<%= f.my_tag :user_id, @user.id %>
```

The [code to make something like that](https://coderwall.com/p/-biuug/custom-form-builders-in-rails) was such a WTF moment for me that I had to physically take a step back from my overpriced macbook pro and take 3 solid, slow breaths before I could get my wits about me and dive into content_tag hell.

### ActiveRecord syntax
I used to be a fan of ActiveRecord, I always thought it had that special something that made interacting with yucky mysql, postgres or sqlite palatable and sane. That is until I realized that it’s hurting me more than it’s helping me. I honestly don’t even know where to start. Wait… it’s coming to me, ok here we go, let’s start with something that should be easy, getting collections out of related objects:

```ruby
current_user.todos.includes(:tags).where(completed: true).order(created_at: :desc).limit(30)
```

I mean, it seems like this does what I want, I want some todos and their associated tags based on the current logged in user, I expect this:

```ruby
[
  {
    todo: {
      name: "todo #1",
      tags: [{name: "tag"}]
    }
  }
]
```

But this doesn’t happen, everything is wrapped up in an object and to get plain jane data out you have to introduce yourself to strange words like serializing and sometimes even gasp, marshaling. Honestly though, being a data marshal sounds like I’m about to have a wild west shoot out in the middle of town: it’s me, my keyboard and [the gang of four](http://wiki.c2.com/?GangOfFour).

### ERB
This isn’t even related to custom form builder helpers, this is just straight up nonsense. If I had a nickel for every time I closed an ERB tag due to editor malfunction I sure as heck wouldn’t have to work anymore because I’d be a rich son of a gun. The idea of learning a whole other syntax on top of ruby and on top of rails’ conventions? I’m just trying to make a fricken website here not send a man to the moon, how many different things do I need to learn here?!

### AR Callback hell
How do you get function reuse on a given event? Like for example when an object is created? Well you type after_create and then you call a method, sweet. Done. Of course what no one bothered to tell me is that the reason I even need these hooks in the first place is because we aren’t just calling regular functions to begin with, we’re calling a complex chain of methods so deep, it makes the marianas trench look like a kiddy pool. What’s the alternative you ask, how can we call a function every time a new database record is made. Well, it’s called a function, and you could just call that function where ever you want to save that thing, you don’t need a callback, you don’t need to learn another thing and get lost in debates about whether or not it’s after_commit on: :create or after_create. You can just call a function.


### Criticism is the sincerest form of make a new framework
Which is what I did, I made yet another full stack framework, except this one isn’t in ruby, it’s in clojure. It also doesn’t have a lot of stuff, it doesn’t have a separate templating language, it doesn’t have an ORM, it doesn’t have AR callbacks or special `content_tag` methods, it uses functions and that’s pretty much it. If you made it this far you’ve got to be interested, check out the [quickstart](https://github.com/coast-framework/coast/blob/master/docs/Quickstart.md) and let me know what you think!

—

Originally posted on [medium](https://medium.com/@swlkr/rails-the-struggle-is-real-e0bf8052e58b)