News for hackers. Stuff that matters.
Re:Learning Ruby: Things I Like, Things I Miss from Python by gls2ro on Tuesday February 16, 2021 @05:25AM (#26152651)
I don't have a recommendation, but here is a quick test I use when looking for a replacement for Rails:

How quick can I create a minimum simple SaaS like application that has the following functionalities:

- User management (Signup/Login/Reset password/Confirmation...)

- Simple payment processing (like have on single plan, one time fee, and after paying the user will see some other default page then not paying)

- Sending emails in HTML and plain text (for user management and after payment is processed)

- Use slugged/permalink like URLs

- Processing some task in async queue

And so far there are a lot of alternatives out there but for me Rails provides the easiest experience to have this up and running quickly as there are already battle-tested gems for almost all these functionalities.

Re:Learning Ruby: Things I Like, Things I Miss from Python by andi999 on Tuesday February 16, 2021 @05:58AM (#26152807)
Just wondering: is rails transactional? What I mean how are race conditions avoided if e. g. two requests are processed at the same time.
Re:Learning Ruby: Things I Like, Things I Miss from Python by brightball on Tuesday February 16, 2021 @09:34AM (#26154176)
It's got a very helpful transaction block wrapper structure that allows you to do some really interesting things with database transactions.

To be perfectly honest, one of the things that I always love about Rails is exactly how good the database layer is with ActiveRecord. I like using the advanced features of my database, especially PostgreSQL, and I've found that it's really easy to do with Rails.

The "Scopes" feature of active record that let's you save small snippets of a query and chain them together is fantastic. I've used it to create complex filter functions that combine full text search and coordinate distance as simple methods that can be attached to any query.

Being able to add a `.search("fender").distance_from(location, 5, :miles)` onto any query made my life so much easier.

It's been a few years, but I wrote about some of my favorites.

https://www.brightball.com/articles/rails-gems-to-unlock-adv...

Re:Learning Ruby: Things I Like, Things I Miss from Python by ryanbrunner on Tuesday February 16, 2021 @07:39AM (#26153312)
Rails has support for database transactions, but depending on what you want to do, things won't be magically transactional all by themselves (that said, it's really just a matter of wrapping transactional code in a block).

There are a couple of footguns in Rails involving transactions - by default, validating uniqueness of a column in Rails will be done at the app layer which is prone to race conditions, and with a typical CRUD model for an application, there's nothing in particular preventing overwrites of model data if say, a field was present on a form and two people were editing it, even if the "later" editor made no changes to that particular field.

When multiple systems and things other than databases (or multiple databases) are involved, you're generally on your own as well.

Re:Learning Ruby: Things I Like, Things I Miss from Python by pbowyer on Tuesday February 16, 2021 @08:53AM (#26153852)
It's important to say that these footguns are not exclusive to Rails. I don't know a single web framework which avoids them - if it exists I'd like to know so I can learn how they do it.
Re:Learning Ruby: Things I Like, Things I Miss from Python by RickSullivan on Tuesday February 16, 2021 @05:32PM (#26159606)
Elixir's Ecto has the best solution to this problem in my experience--it doesn't do database validations on things like uniqueness, but provides easy error handling when constraints are hit.

It encourages you to write validations for things that don't need to hit the DB, but actually uses the DB for handling constraints, since it's the real source of truth for data consistency.

Re:Learning Ruby: Things I Like, Things I Miss from Python by andi999 on Tuesday February 16, 2021 @10:06AM (#26154492)
Thanks. So typical CRUD applications usually run on luck? (or on not beeing unlucky if the average number of request per hour is not so high).
Re:Learning Ruby: Things I Like, Things I Miss from Python by msbarnett on Tuesday February 16, 2021 @11:58AM (#26155979)
Not really?

Most CRUD applications go the one extra step of putting a uniqueness constraint on the column instead of just relying on the app layer validation, and comparing hidden time stamps on the form if multiple people might edit the same row simultaneously. It’s exceedingly straightforward.

Did you really think thousands of web apps up to and including GitHub and shopify were squeaking by on blind luck? If basic database transactions and integrity weren’t doable in Rails, that’d have had to have been fixed years ago.

Re:Learning Ruby: Things I Like, Things I Miss from Python by andi999 on Tuesday February 16, 2021 @12:02PM (#26156024)
Any reference how this is best done with rails?
Re:Learning Ruby: Things I Like, Things I Miss from Python by msbarnett on Tuesday February 16, 2021 @12:28PM (#26156343)
Depends on what you mean by “this”, I suppose.

Most of your basic questions are covered by the starter Rails Guide for ActiveRecord, eg) transactions, validations, how to add a uniqueness constraint to the DB in a migration

https://guides.rubyonrails.org/active_record_basics.html

The ActiveRecord Queries guide also covers some mechanisms for handling row-level write contention

https://guides.rubyonrails.org/active_record_querying.html#l...

Re:Learning Ruby: Things I Like, Things I Miss from Python by gls2ro on Tuesday February 16, 2021 @06:25AM (#26152933)
In case of DB:

I think ActiveRecord has #lock (see https://api.rubyonrails.org/classes/ActiveRecord/Locking/Opt...) and that together with #transaction (https://api.rubyonrails.org/classes/ActiveRecord/Transaction...) are enough for my use cases.

In case of file uploads to cloud providers: there I don't know for specific method to help with race conditions when transforming the resources.