Creează un cont pentru a te abona la acest blog și a-i urmări articolele pe pagina Lectură.
-
One of the ways I have been using coding agents these days is to prototype small UI changes in an existing project.
-
This week I made a refactor to remove a job (ActiveJob::Base) that was used only in recurring.yml, and call a class method directly instead.
-
I just released md_record, a Ruby gem that provides an ActiveRecord-like interface for markdown files with YAML frontmatter.
-
I have some posts about using lateral joins in rails to fetch the “top N” of each record.
-
Yesterday, I found myself struggling with “litesearch”, and in my frustration, I decided to create a simple “Searchable” module to perform a “LIKE” search but with a cleaner interface/API.
-
I was reading about shoes.rb and, while scanning the book and walkthrough, I discovered a pattern that caught my attention for its power and simplicity.
-
N+1 queries are not always a problem, but I have seen that most of the n+1 queries that are really a problem are when we need to fetch data to compute something.
-
Imagine that you want to truncate a filename, but you want to keep showing the extension of the file.
-
Imagine that you are building a custom CMS.
-
Imagine that you have a form to update a record (let’s say a product record) and inside the form, you are showing a list of images, and each image needs a button to remove it.
-
If you want to add images to a record but you don’t want to use a JavaScript plugin or write any custom JavaScript, you can use a regular file field, Active Storage, and vanilla Rails.
-
If you want to add many attachments to a record using just a file field, but you don’t want to remove the previous images from the record on every update, like in the following code: <%= form_with(model: product) do |form| %> <%= form.label :images %>
-
When saving computed values in the database in your rails app, you must be aware that is possible to find unexpected errors in the result thanks to race conditions.
-
When saving computed values in the database in your rails app, you must be aware that is possible to find unexpected errors in the result thanks to race conditions.
-
When saving computed values in the database in your rails app, you must be aware that is possible to find unexpected errors in the result thanks to race conditions.
-
When saving computed values in the database in your rails app, you must be aware that is possible to find unexpected errors in the result due to race conditions.
-
I have already written about how you should be aware about race conditions when saving a computed value, because you could save a wrong value.
-
When saving computed values in the database in your rails app, you must be aware that is possible to find unexpected errors in the result thanks to race conditions.
-
In Rails, sometimes you will need to save counts or custom computed values, where the default counter cache will not be enough.
-
Imagine that you are creating a record (let’s say a tweet), and on creation, you want to add the tweet to the page and also update the tweets count in the page… But you want to update the content, not just for the current user, but for all the users in the
-
Do you want to build powerful admin interfaces with little code, but you are not sure if you want to jump into a full admin solution like Active Admin, Administrate or Avo?
-
Have you ever needed to get the most recent N posts for each user in rails, but didn’t know how to do it without using map?
-
Have you ever needed to get the most recent N posts for each user in rails, but didn’t know how to do it?
-
Have you ever wanted to just create an active record example to someone in your team without thinking in the database setup?
-
Display the count of an association could look like a simple task, but in some cases it can give you real troubles.
-
Have you ever needed to get the most recent post for each user in rails, but didn’t know how to do it without using map?
-
Sometimes calculating the count of a collection on every page render, even in SQL, is not the best option.
-
Maybe you have heard about the counter cache feature.
-
Maybe you have heard about the counter cache feature.
-
At least for me it is very common to use the within method in capybara, to match the dom_id output.
-
Imagine that you need to put the number of likes for each post in a list, but avoiding n+1 queries. posts.each do |post| post.likes.count # n+1 queries end One way to avoid n+1 queries here, is to preload the association and the count the records in ru…
-
With Rails/ActiveRecord, you can count the records in an association using three methods .count, .length, .size.
-
I want to share with you my “Active record playground template”.
-
It is very common the need to preload an association then filter that association and then use the filtered collection.
-
I have seen that some people think that you have to forget about Rails and Hotwire, if you want to use React or another Javascript framework to build a Single Page Aplication, but this idea is not true.
-
When you start a new app or when things start to get complicated on the frontend side of your rails app, I think that it is normal to start thinking if you should split the app into a rails backend and a frontend with react, vue, or other javascript frame…
-
If you are new with rails and hotwire, it could be useful to know that you can pass an object to the turbo_frame_tag and it will use a string representation of that object as an id.
-
I built a tool to comples css classes like this… styles = Styler.new do style :default, ["pa3", "white", "bg_blue"] style :danger, [default - "bg_blue", "bg_red"] end styles.default.to_s # => "pa3 white bg_blue" styles.danger.to_s # => "pa3 white bg_…
-
This is a guide to help you build “inline CRUDs” with rails and hotwire, where you create and edit records in the same page.
-
Here I want to show you how you can build “remote modals” (modals where the content is requested to the server), submit forms embedded in them and handle errors, with rails, hotwire and bootstrap.
-
A very common task as a Rails developer is to let the user filter a list with a combination of search fields and selects.
-
One of the things that I want from css is to have to possibility to compose already defined styles, to define new ones… If you try to write “Semantic CSS”, you will find a hard time trying to avoid the repetition on things that look the same but are diffe…
-
If you work with capybara and you are constantly searching for capybara helpers, maybe to have this little cheatsheet at hand could work for you.
-
Maybe you are already familiar with includes or preload, but you know that a lot of the time you will need more than just preload(:comments).
-
Although there are tools that can help you detect n+1 queries before they hit production, I think that is good to be able to identify n+1 queries directly by watching your logs… Not all the tools will tell you exactly that you have n+1 queries, and someti…
-
Maybe you already know that “fixing” an n+1 queries problem can hurt the performance of your app… But even if you already know it and also understand how it can happen, it could not be obvious how to know if this is will happen with your fix.
-
When you are working with SQL, to use information from other tables you would use a JOIN… And if you are just starting to learn ActiveRecord comming from SQL, you could think that by using the joins method you will be able to later use the data from the a…
-
I want to share with you an example application to help you visualize why “fixing” an n+1 queries problem, can hurt the performance of your application if you preload assocations with too many records.
-
Sometimes people say that “fixing” some n+1 queries could hurt performance… Maybe this phrase can be confusing, because if you have not been exposed to a lot of n+1 queries problems, it could be hard to imagine how it can be possible.
-
I want to tell you that I have added a new section to the guide for preloading associations in rails, to introduce you to something I call “Preload objects” that will help you build complex preloads for those cases when you can’t find a way to do what you…