Hacker Newsnew | past | comments | ask | show | jobs | submit | benblue's commentslogin

I agree that ActiveRecord isn't particularly opinionated about how to deal with updates to batches of records, but there are multiple ways of approaching this and AR won't get in your way.

upsert_all[1] is available to update a batch of records in a single write that does not invoke model callbacks.

activerecord-import[2] is also very nice gem that provides a great api for working with batches of records.

It can be as simple as extracting your callback logic and a method (def self.batch_update) and running your callback logic after the upsert.

[1] https://api.rubyonrails.org/classes/ActiveRecord/Relation.ht... [2] https://github.com/zdennis/activerecord-import


By upsert_all not invoking model callbacks, it's admitting that the ActiveRecord approach doesn't scale.

"It can be as simple as extracting your callback..." Isn't this the kind of repetitive thing a framework should be doing on your behalf?

To be fair, ActiveRecord isn't a fault Rails invented. Apparently it's from one of Martin Fowler's many writings where each model instance manages its own storage. Even Fowler seems to say that the DataMapper approach is better to separate concerns in complex scenarios.


TBF no framework will do everything perfectly, and having clean escape hatches is pretty good in itself.

Even outside of batch processing, there will usually be a few queries that absolutely benefit from being rewritten in a lower layer of the ORM or even plain SQL. It's just a fact of life.


I write system tests like this with the REPL often. I just change the Capybara driver from its usual headless_chrome to chrome and put a debugger (or pry) breakpoint in the RSpec example. From there I just "drive" from the REPL, testing my finders/matchers and building up the test example as I go. As you suggest, being able to use dev tools directly in the browser being driven by Capybara is massively helpful during this stage.


at one point i started to make a gem called "dora" where you could "explore" the page with methods around the capybara driver, but never finished it. for example: page.find_blog_posts.highlight_all would draw a blue box around each "blog_post" element.


For a greenfield project I'd probably reach for Inertia.js though I don't have any experience with it aside from reading the docs.

If you just want to use Vue for your rendering layer, you can can do that using a very minimal partial that renders the root element and loads the JS to mount the component. This example should get you started (Vue 2 syntax):

https://gist.github.com/yourboyblue/834aac9c427a97037dd49694...


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: