Chris Oliver

Chris Oliver

Joined

297,200 Experience
100 Lessons Completed
295 Questions Solved

Activity

Posted in How to use Active Search in Rails Discussion

Hey Kevin! Glad the video helped. Claude is a big help for us too.

They work fine side by side because they solve different problems and don't touch each other's code.

Ransack turns params like title_cont or published_at_gteq into SQL WHERE clauses on an Active Record relation. It works well for admin tables, sortable columns and structured filters. But it's still a LIKE query on your database, so there's no relevance ranking, no stemming, and it gets slow on large text columns.

ActiveSearch sends your text to a search index. That can be Postgres tsvector, SQLite FTS5, or Meilisearch, Elasticsearch, Typesense and others. It gets back ranked document ids and then loads the records. You get real full-text search with relevance scores and highlighting, and you can change backends without rewriting your queries.

The one place they don't mix well is chaining a Ransack relation onto a search. ActiveSearch picks the page of hits in the index first, so this doesn't do what you'd expect:

Article.search("rails", scope: Article.ransack(params[:q]).result)

The scope: option only controls how the matched records get loaded. It doesn't filter the search. Anything your Ransack conditions exclude is just dropped from that page (counted in results.dropped), so your pages and counts come out wrong. To filter a search, put those fields in the index and use ActiveSearch's own filters:

Article.search(params[:query])
  .filter(account_id: current_account.id, status: "published")
  .filter(published_at: 1.month.ago..)
  .reject(featured: false)

My rule of thumb:

  • Ransack for admin screens and structured filters on columns, where you don't need text relevance.
  • ActiveSearch for the search box users type into, where relevance matters, with the filters you need indexed next to the text.

One thing ActiveSearch doesn't do yet is aggregations, so no faceted counts like "Rails (42), Hotwire (17)" next to your filters. If you need those, run a SQL GROUP BY alongside the search for now.

You can have both in the same app, even on the same model. Ransack is mature and stable. ActiveSearch is still alpha and its API may change, so keep that in mind if you use it in production.

Hey Harsha,

Rails is pretty much the same regarding APIs. Kamal, SolidQueue, etc are all great to know, but aren't specific to APIs.

We have several series that talk about what's new in each Rails release.
https://gorails.com/series/rails-8-1
https://gorails.com/series/rails-8-0
https://gorails.com/series/rails-7-2
https://gorails.com/series/rails-7-1
https://gorails.com/series/rails-7-0

If you want to see all of the latest stuff put together, the Domain Monitoring SaaS series builds an actual product from scratch to production with Rails: https://gorails.com/series/domain-monitor-saas

Would you be interested in learning about how we use Packer to build custom Ubuntu server images?

File uploads seem easy because they're so commonplace, but they're actually quite complex!

Posted in ActiveRecord in_order_of Discussion

I always forget this feature exists, but it can really come in handy. Much cleaner than writing your own SQL for this.

Posted in Invoker Commands API Discussion

One of the best new browser features. 🔥

You'll want to have a separate model for the profile (I guess a Venue or Musician model?), that way they can live on their own. You can have an optional "owner" which can determine if it's claimed or not.

For an unclaimed profile, you'll need to figure out some way of handling that. Obviously, you don't want random people taking over profiles so there would need to be some sort of verification process. You can probably have them submit some proof and you can manually approve it on the backend.

If you require someone to be signed in as a User, then they could submit a form to claim ownership of a Venue or Musician profile. When you "approve", it would just be assigning the owner_id column on the record to the User's ID basically. Does that help?

Posted in Recurring Domain Expiration Syncing Discussion

Hey all! I've updated this lesson to include find_each in the SyncAllJob as well as a test to ensure it queues up the correct jobs. 👍

Posted in Ruby's Tap Method Discussion

Just tap it in. Give it a little tappy. Tap tap taparoo.

Posted in Checking Domain Expirations With RDAP Discussion

Eric, add the openssl gem to your Gemfile to fix that error. Should be fixed in Ruby 4 too as that'll include the latest openssl built-in to Ruby.

Posted in Checking Domain Expirations With RDAP Discussion

Excited to kick off a SaaS product series. Should we build more end-to-end projects like this?

Posted in Module extend self Discussion

The point of extend self is you can use it both ways.

Posted in Module extend self Discussion

This is such a handy feature of Ruby. I was amazed when I first learned about it. Really makes modules useful for any situation, not just being included in another object.

Posted in Foreign Key on_delete db Constraints Discussion

The add_foreign_key docs show all the various options for on_delete and others: https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-add_foreign_key

Posted in Path update to RoR 8?

All those projects work exactly the same in Rails 8.

Posted in Pro

Hey Francisco, just cancel your subscription after 3 months 👍

Posted in Morse Code with Ruby - Part 1 Discussion

.. / .-.. --- ...- . / --. --- .-. .- .. .-.. ...

Posted in Customizing Rubocop Rails Omakase Rules Discussion

Do you have any favorite Rubocop rules?

Posted in Ruby Pattern Matching Discussion

What version of Ruby added this?

@Nathan nope, I don't think there were any changes. If you run into any issues, let me know. 👍