DEV Community

Discussion on: Rails: The Struggle Is Real

Collapse
 
kida001 profile image
Brian Vogelgesang • Edited

Is this some clickbait article to plug your new framework? Maybe you don't understand Rails? None of your points are flushed out, or in my opinion actually point to some of the issues Rails does have.

AR Callback Hell
Just because you can use those hooks, doesn't mean you should. Any PR I review that doesn't have a good reason for a before/after hooks would get rejected. Create explicit objects to handle your business logic, don't stuff them in the model where they get executed any time someone wants to create or update a DB object.

If you're in callback hell, it's because you made poor architecture decisions.

ERB
What is so complex about ERB, it's no different from any templating language I've used. You write HTML, and when you want to escape and execute code, you use <% insert_code_here %>.

"If I had a nickel for every time I closed an ERB tag due to editor malfunction..."
Maybe you should learn how to use your text editor

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

Do you know what SQL it takes to create the above AR Syntax?

SELECT *
FROM todos
WHERE completed_at is true AND user_id is $user_id
ORDER BY created_at desc
LIMIT 30;

Are you complaining that AR is too complicated for you? I'd say it's a hell of a lot cleaner and easier.

And yes, actually, the practice for any up-to-date rails application is to use a Serializer, which will eager load your associations if they're requested and let you abstract your response where it belongs, outside of the controller.

If you'd done any light reading on Rails, you'd take advantage of the things it offered, likes scopes, serializers, and pagination...

Serializer:

class TodoSerializer < ActiveModel::Serializer
  attributes :title, :description, :completed

  has_many :tags
end

Controller:

def completed_todos
  render json: Todo.where(completed: true), include: :tags
end

It literally requires that to return a JSONAPI compliant response with ActiveModel Serializers and Kamanari.

Your arguments are pretty moot, but maybe it's because you're trying to plug your framework. You would have done a much better job if you just explained the benefits of what your offering, without trying to shit on something.

Collapse
 
swlkr profile image
Sean Walker

I had to do a double take because I thought you were DHH for a second.

Thanks for taking the time to teach me all of these things! I needed it!