[HN Gopher] Rails 6.1
       ___________________________________________________________________
        
       Rails 6.1
        
       Author : jonathanhefner
       Score  : 157 points
       Date   : 2020-12-09 20:13 UTC (2 hours ago)
        
 (HTM) web link (weblog.rubyonrails.org)
 (TXT) w3m dump (weblog.rubyonrails.org)
        
       | ksec wrote:
       | >Error Objects
       | 
       |  _Active Model's errors are now objects with an interface that
       | allows your application to more easily handle and interact with
       | errors thrown by models. The feature was implemented by lulalala
       | and includes a query interface, enables more precise testing, and
       | access to error details._
       | 
       | This has been in the work since Rails 5.x and I believe Lulalala
       | extracted it from his work on Gitlab. And it was lot of hard
       | work.
       | 
       | Since both Github and Shopify now runs on Master, I dont think
       | there are any other open source web framework that is more battle
       | tested than Rails.
       | 
       | Still waiting for New Magic though.
        
         | marinhero wrote:
         | I'm out of the loop. what is New Magic?
        
           | maxfurman wrote:
           | DHH has been teasing something called "New Magic" on Twitter
           | but beyond that we don't know much.
        
           | ibraheemdev wrote:
           | DHH mentioned "NEW MAGIC" when he released the Hey stack on
           | twitter [1]:
           | 
           | > The HEY stack: - Vanilla Ruby on Rails on the backend,
           | running on edge - Stimulus, Turbolinks, Trix + NEW MAGIC on
           | the front end
           | 
           | There has been a lot of speculation since then on what New
           | Magic is. It was supposed to release at the same time as
           | hey.com but they decided to postpone it till later. Many
           | people think/hope that it is something similar to Phoenix
           | LiveView
           | 
           | 1: https://twitter.com/dhh/status/1275901955995385856
        
         | Fellshard wrote:
         | Couple of changes here that would be directly useful in what
         | I'm working on. Does boost my confidence - as a dev newer to
         | Rails - that the rough spots I'm spotting are recognized by
         | other folks as well. It also tells me I can be more proactive
         | in proposing changes, or at least in addressing those rough
         | spots.
        
       | sbuccini wrote:
       | Lots of good stuff in here, including much more support for using
       | UUIDs as PKs.
       | 
       | My favorite new feature is "delegated type" in ActiveRecord to
       | offer a new way to map class hierarchies onto database tables. I
       | wrote a blog post about it[0], but the actual PR is very readable
       | as well[1].
       | 
       | [0] https://www.stevenbuccini.com/how-to-use-delegate-types-
       | in-r...
       | 
       | [1] https://github.com/rails/rails/pull/39341
        
         | tomca32 wrote:
         | > Lots of good stuff in here, including much more support for
         | using UUIDs as PKs.
         | 
         | I missed this. Going through the changelogs the only thing I
         | found is support case-insensitivity for pg UUID types. Is that
         | what you meant?
         | 
         | I really think that not supporting UUID PKs is one of biggest
         | issues with Rails. You can go around it and maybe even use a
         | gem for it, but that's still a bit risky.
        
           | treis wrote:
           | I use UUID PKs in Rails today. What support do you think it
           | is missing?
        
         | skipants wrote:
         | Seems really nice. It's just a Rails abstraction for Multi-
         | table inheritance (MTI) but to me that was sorely needed. MTI
         | always felt much more manageable to me than Single-table
         | inheritance but the latter was the only one with built-in
         | support in Rails, until now.
        
         | ilikepi wrote:
         | We implemented something like this on our own. We have child
         | classes that inherit from an AR-backed parent, and on the
         | parent we implement an instance method that transforms it (via
         | #becomes) to the appropriate child based on the value of an
         | attribute. The final piece is another attribute that stores a
         | serialized object of child-specific attributes, and other
         | methods that dynamically define attribute readers at boot time.
         | It'll be nice to migrate to this new feature to free ourselves
         | from the burden of that last piece in particular.
        
         | polutropos wrote:
         | Does a "delegated type" work with preloading associations, ala
         | "includes"? This remains a pain point with many polymorphic
         | associations in Rails, but not sure how the new functionality
         | handles if, if it does at all.
        
           | sbuccini wrote:
           | Based on this GitHub comment[0], it appears the answer is yes
           | although it requires a little additional customization out of
           | the box to prevent N+1 queries..
           | 
           | [0] https://github.com/rails/rails/pull/39341#issuecomment-72
           | 725...
        
             | inopinatus wrote:
             | In conjunction with Rails's "russian-doll" caching, N+1
             | queries are (or at least, can be) a good thing.
             | 
             | This sounds counterintuitive; but, in the common case of
             | read-heavy services, N [?] 0 after the first access. When
             | something changes, subsequent views end up loading &
             | rendering the one record that changed, instead of
             | preloading an entire collection.
             | 
             | However, achieving this in practice requires some care in
             | the nesting of view partials and records.
             | 
             | c.f. DHH in
             | https://www.youtube.com/watch?v=ktZLpjCanvg&t=4m27s _" N+1
             | is a feature"_
        
       | _gtly wrote:
       | The beginning of Horizontal Sharding support is great to see.
       | 
       | More refined release notes here:
       | https://edgeguides.rubyonrails.org/6_1_release_notes.html
       | 
       | And yet more release notes:
       | https://weblog.rubyonrails.org/2020/12/9/Rails-6-1-0-release...
        
       | mhoad wrote:
       | It's a really nice time to be a Ruby / Rails developer. Rails
       | itself has made some really nice improvements with this release
       | and there is also the "NEW MAGIC" should be following in the next
       | couple of days which is currently being sold as what Rails was to
       | the back end, this will be to the front end.
       | 
       | Ruby 3 is also just a few days away which brings optional type
       | checking to helps add some additional structure to larger code
       | bases.
       | 
       | Then in the wider community you have projects like Hanami 2.0
       | looking to launch next year which aims to bring all of the
       | structure of "clean architecture" approaches and best practices
       | with the simplicity and expressiveness of Ruby.
        
         | Dirlewanger wrote:
         | >Ruby 3
         | 
         | Oh shit, I didn't realize that that's the scheduled Christmas
         | release. Finally, all strings frozen by default!
        
         | freehunter wrote:
         | Man I'm hoping NEW MAGIC is like Phoenix LiveView. As a Rails
         | dev I started looking into the Elixir/Phoenix world just for
         | LiveView but I don't _really_ want to switch languages... I
         | just want that new magic that LiveView offers. I know there are
         | gems for Rails but I 'd prefer if it was baked-in and
         | officially supported.
        
           | mhoad wrote:
           | Depending on your patience you can go and take a look at a
           | real life implementation of it at https://app.hey.com since
           | they enable source maps.
           | 
           | What the actual developer facing API is going to look like
           | however is another question. I do kind of worry that given
           | how much is has been talked up by DHH in particular that it
           | is going to struggle to live up to the hype.
           | 
           | Either way, I am excited to see something new in the Rails
           | front end space, that has felt like it was lacking a LOT of
           | structure.
        
             | inopinatus wrote:
             | I was sold on hey.com's UI design already because it's
             | using <details><summary> for dropdown menus.
             | 
             | The really fun part, though: the summary content isn't just
             | a menu icon, it's a trigger for some (currently
             | unpublished) Turbolinks variant. The menu content is loaded
             | (and subsequently 304'd) dynamically as a server-rendered
             | partial (sans layout).
             | 
             | Most tellingly, if you visit the menu content's XHR URL
             | with regular browsing then hey.com renders that menu as the
             | sole content in a page layout.
             | 
             | We can't see the server-side parts yet, but if that becomes
             | an out-of-the-box end-to-end behaviour within Rails, then
             | in conjunction with Stimulus 2 and Action Cable I'm stoked
             | about the possibilities. Especially so since I have a
             | mission to replace all my dropdown & modal boilerplate with
             | <details><summary> and <dialog> elements, and I like to
             | build services that still work if JS is disabled. But it's
             | also good for mundane stuff like progressive form
             | validation in line-of-business apps.
        
               | jxf wrote:
               | > Especially so since I have a mission to replace all my
               | dropdown & modal boilerplate with <details><summary> and
               | <dialog> elements, and I like to build services that
               | still work if JS is disabled.
               | 
               | Can you elaborate on why `<details><summary>` is
               | specifically exciting to you?
        
               | mhoad wrote:
               | Based on my casual browsing of the code I assume that it
               | pushes small HTML fragments via WebSockets whenever the
               | backend state changes on a given ActiveRecord model. It
               | covers things like automatically updating the state of a
               | model on a page, adding, removing, reordering elements
               | etc all without any custom code so long as things are
               | wired up correctly.
               | 
               | Basically, all the "re-activeness" of an SPA but without
               | ever having to worry about the concept of client side
               | state management at all.
               | 
               | Edit: I am a grumpy old man in web-dev years who hadn't
               | ever really looked into Phoenix Live View before now but
               | after watching a video on how it works, yes, my
               | understanding is that it works basically the same way.
        
           | AlchemistCamp wrote:
           | > I started looking into the Elixir/Phoenix world just for
           | LiveView but I don't really want to switch languages...
           | 
           | Yes, you want to _add languages_! Join us...
        
           | aczerepinski wrote:
           | LiveView is awesome - I'd be pleasantly surprised if Rails
           | were able to pull off something that good with Ruby's more
           | limited capacity for concurrency.
        
             | [deleted]
        
             | ibraheemdev wrote:
             | Ruby 3 is putting a lot of emphasis on concurrency with the
             | new (experimental) Ractor Actor model [1] and the Fiber
             | Scheduler [2]. Concurrency in Ruby is getting a lot better.
             | 
             | 1: https://github.com/ruby/ruby/blob/master/doc/ractor.md
             | 
             | 2: https://bugs.ruby-lang.org/issues/16786
        
       | onnnon wrote:
       | Here's the Railties diff if anyone needs:
       | 
       | http://railsdiff.org/6.0.3.4/6.1.0
        
       | kadabra9 wrote:
       | I did a bunch of work in rails prior to the 3.0 days ( probably
       | around 2013 or so), but then switched domains to work more in
       | data engineering.
       | 
       | When I came back to it to scratch an itch for some pet projects,
       | I barely recognized it. I felt completely lost.
       | 
       | Life moved pretty fast, I guess. Are there any good resources out
       | there for someone from the 2.x days to get back to speed?
        
         | 30minAdayHN wrote:
         | I fall in this same bucket. I still refer to the old railscasts
         | now and then. I use rails for my hobby projects.
         | 
         | Currently, I depend on Rails Guides, and I think they do a
         | pretty good job. Would be good to know other resources.
         | 
         | https://guides.rubyonrails.org/
        
           | mhoad wrote:
           | Railscasts sadly is no longer but now the two big ones that
           | operate in that space are GoRails and Drifting Ruby. Some
           | other non-screencast resources I like however are Boring
           | Rails and Playbook Thirty Nine (ebook of tips and tricks from
           | the trenches of a real life smalltime Rails SaaS business)
        
         | xionon wrote:
         | For what it's worth, the 2->3 update was by far the most
         | consequential; they merged in Merb, rewrote how routes and
         | controllers worked, and completely flipped expectations on how
         | JS and views should work.
         | 
         | Rails 3->6 has had far fewer major user-facing architectural
         | changes, and consisted mostly of new tools and APIs. A lot of
         | stuff they added used to be handled by gems - password hashing,
         | attachments, background jobs, caching, etc. all got rolled into
         | the core framework.
         | 
         | Another comment mentioned https://guides.rubyonrails.org, which
         | is good. I would focus on the new routing style, REST
         | controllers, forms, and strong params; once you wrap your head
         | around those, the rest will probably fall into place, or could
         | be ignored completely.
        
       | simonw wrote:
       | "rafaelfranca released this 1 hour ago * 324 commits to master
       | since this release"
       | 
       | That's the sign of a very actively maintained project!
       | 
       | (To clarify: those 324 commits didn't all happen in the past 60
       | minutes, but it does show that there's a huge amount of
       | development activity going on around Rails core)
        
         | jamie_ca wrote:
         | Yeah, I think this is indicative of a feature lock during the
         | RC period, and once the release is cut that opened up a bunch
         | of PRs that were just waiting in the wings.
        
       | [deleted]
        
       | bleonard wrote:
       | It's cool to see "DHH" still in these changelogs.
        
       ___________________________________________________________________
       (page generated 2020-12-09 23:01 UTC)