I have already shared a way of implementing a “read-more” behavior truncating by the number of lines instead of the number of words.
But now I want to share how you can do it using the line-clamp
css property.
Are you looking for a way of implementing a “read-more” behavior truncating by the number of lines instead of the number of words?
Are you working with capybara?… Are you constantly searching for capybara helpers?
Here is a small reference with some of the most used methods/helpers.
Imagine that you want to refactor this…
expect(row).to have_css("[data-role=description]", text: "Desc 1")
expect(row).to have_css("[data-role=amount]", text: "$250.00")
into this…
expect(row).to display_entry_with("Desc1", $250.00)
This is a little reference of tools to help you detect n+1 queries on a rails app.
Do you need more practice to understand the difference between “includes”, “preload”, “eager_load” and “joins”?
Here you will find a set of exercises to help you understand how you can use this 4 methods.
You can find the code on bhserna/preloading_quiz
Read moreI am currently working on a kind of “presentation object” that I called IdealPayments::GlobalStats
.
This object will be used in two places, to display a graph and to show the data in a page where we can see all the “ideal payments”.
In my imagination...
Read moreDo you know “in theory” the difference between “includes”, “preload”, “eager_load” and “joins”, but you still think that you need more examples to really understand how to use them?
Here you will find a set of examples to help you understand how you...
Read moreDo you know “in theory” the difference between “includes”, “preload”, “eager_load” and “joins”, but you still think that you need more examples to really understand how to use them?
Here you will find a set of examples to help you understand how you...
Read moreAre you using Active Storage to handle file uploading to the cloud (maybe AWS) and you want to know how to attach an uploaded file to an email?… But you are not familiar with the Active Storage and Action Mailer APIs?
I answered this question on reddit...
Read moreEven if you already know what is the difference between includes
, preload
and eager_load
, maybe is not that clear when is better for you to use one vs the other.
Are you dealing with includes
, preload
, eager_load
and joins
, maybe fixing some n+1 queries, but you are not really sure what’s the difference between all of them?
Would you like to be able to say things like… “Here I will use preload
instead of
A common cause of n+1 queries is fetching the “latest-N-of-each” record on a list of records.
Some examples of this problem are trying to get…
Do you struggle fixing N+1 queries because is hard for you to detect why ActiveRecord seems to ignore your “includes”?
Wouldn’t it be nice to just see some piece of code and know when the query will execute?
Well… this exercise will try to help you...
Read moreDo you have a method that works fine with a single record, but when you use it on a list causes N+1 queries?
Imagine that you have a model like this…
When you are trying to solve an n+1 problem, hopefully you will find different ways to solve it. But what is the one that you should use?
Talking specifically about the fixes that I share to you to solve the “latest comment” n+1 queries problem… I...
Read moreWhat fix should you pick for your “latest-comment” n+1 queries problem?
One example of this problem is trying to get the latest comment on a list of posts, but there are others, like the last review in a list of products, or the cheapest price, or...
Read moreDo you have to fetch the latest “x” of each record? Not sure how to avoid the n+1 queries?
Hopefully you will find different ways to solve it. But what is the one that you should use?
You can search the internet, but opinions can be overwhelming...
Read moreDo you have to fetch the latest “x” of each record?
One example of this problem is trying to get the latest comment on a list of posts, but there are others, like the last review in a list of products, or the cheapest price, or the latest payment...
Read moreWhat fix should you pick for your n+1 queries problem?
When you are trying to solve an n+1 problem, hopefully you will find different ways to solve it. But what is the one that you should use?
You can search the internet, but opinions can be overwhelming...
Read moreDo you have a method that works fine with a single record, but when you use it on a list causes N+1 queries?
One example of this problem is trying to get the latest comment on a list of posts, but there are others, like the last review in a list of...
Read moreAre you stuck trying to build a form to save more than one record?
Rails form helpers are really easy to work with when you are working with one ActiveRecord model… but what happen when you need to create a form to save multiple records?… how do you...
Read moreDid you implement a feature that does work, but has resulted in using multiple conditionals in your controller and views?… Are you wondering if there is a better way to do what you just did?
Maybe your problem is that you have a hidden abstraction...
Read moreDo you have a method that works fine with a single record, but when you use it on a list causes N+1 queries?
Maybe, you are building a rails app and you want to fetch a list of posts with the latest comment (or something similar)…
You have a model...
Read moreHe estado leyendo un libro muy interesante que se llama, “A mind for numbers” de Barbara Oakley, Ph.D.
En el libro me topé con una técnica, muy interesante que le llaman “Memory Palace”, me llamó mucho la atención, porque la técnica esta realmente...
Read moreDid you complete a Ruby on Rails tutorial, but want a more focused practice on Active Record?
Do you know other languages and frameworks and want to learn the basics of the magic on Active Record?
As I said in the last post as ruby/rails developers is very common to start our projects with something very similar to the Rails scaffold…
For us, ruby/rails developers is very common to start our projects/apps with something very similar to the Rails scaffold….
If you are thinking in trying Stimulus.js in your project, maybe this little “before and after” can help you to decide.
As I wrote in the previous article about using end-to-end tests in your TDD cycle… This kind of tests can be very helpful in some situations, and I think that is a good thing to try if it works for you and your current project.
Maybe you have always thought that TDD is about making unit/micro test first… And that is true for some people, other people feel more comfortable starting the cycle with an end-to-end test… And you could be one of them.
But sometimes is not very clear how to do it, because when you are doing TDD…
If you are here, maybe it is because you also like fast tests!… I really like fast tests, and for that reason (and some others…) I always try to decouple my code from Rails and other frameworks…
I have already told you that when you are doing TDD with a use case approach, is better to use mocks to design your dependencies instead of been tight to a given interface, because this can help you to decouple from your dependencies following the Dependency Inversion principle.
Have you had started a project trying to do TDD “the right way”, writing “unit tests” for every class and method, trying to hit that famous 100% coverage….
… And then few months later, rewriting many of them just for a little change or refactor!
Have you been in that situation when you are “mocking” something and you feel that you are not testing anything?
I have already told you that organizing your code in use cases can help you to start your projects using TDD, and also I gave you a tip on how you can organize your app in use cases.
But even if you know what your code should do, is not so obvious how you should structure your tests…
I have already told you that organizing your code in use cases can help you to start your projects using TDD … And other people also recommend it for other purposes… You really should try it!
The problem is, that is not really obvious how to do it!…
After reading a lot of questions and answers on TDD and unit testing, are you still struggling to find the answer to… Where to start from?…
Are you new to mock objects? Are you trying to learn how to use them? Are you looking for some “hello world” examples for Mock Objects?
Mock objects can be a really good tool sometimes, but not always. This is a guide, to help you learn how and when you can use them.
Do you want to know how you can use a test double or mock to test the creation of a record? Are you looking for an example of using mocks?… Maybe this post can help you =)
There are different practices, that I know, to test that an email was sent in Rails…
Do you want to know how dependency injection can help you and your team to actually doing less work?
I have an story for you…
Is a common problem in a Rails app to have very slow test suites. There are a lot of test suites that need more than 10 or even 30 minutes to run!…
Is your app in this group?
Maybe you or your team have decided to code “in the right way” and go hard on TDD and unit testing on your Rails app…
Are you struggling trying to define what to test on your unit tests? Maybe is easier for you to identify what to test on your feature tests or system tests because the user story or approval criteria, in a certain way “tells you” what to test or what is expected to happen.
But with your unit tests is different…
Do you struggle with understanding what to test and how to test it?… Maybe you know that “you need to test the behavior of your objects”, but of those behaviors, what do you test?, and how do you test it?… are you looking for some kind of simple steps or methodology to apply? a repeatable process?
Do you have problems deciding what to test or how to test you rails app? Don’t worry, this is a very common problem… I think that there are a lot of reasons why this is hard for many people, but I have found that one of the problems is that are many ways to do it.
Imagine that you have the next controller action that works, but when you see it you feel that you can make it cleaner.
Estas preguntas me vienen constantemente, y hoy fue una de esas veces… Estuve trabajando en https://www.briq.mx/ construyendo una estructura de datos que debería tener información de varias fuentes de la aplicación.
En los últimos proyectos que he trabajado, tanto solo como en equipo, poco a poco he ido descubriendo ciertas practicas o reglas que usamos y que quiero compartir porque creo que también te pueden servir.
En esta idea de “Rails is not my app” es necesario definir cuales son las cosas que va hacer tu aplicación y cuales va a delegar.
This is are the slides of a presentation that I gave at the Ruby Meetup Monterrey, the last year.
Maybe some of you know that I am planning to get marry the next year. If not know you know =).
Talking about object oriented programming, Sandy Metz propose that when you are testing “outgoing messages with side effects” what you should do is just assert that the “outgoing message” has been sent. For example in ruby we can do something like…
Maybe you are in this transition to become a professional programmer (congrats!!) and you have seen that if you want to be “a professional programmer” you have to use TDD and test all your code.
Esta es una pequeña guía aprenderas lo suficiente de git para integrarte a tu equipo de desarrollo.
I want to show you a way you can “draw a line” between your application “main logic” and your Rails controllers.
Lately I have been working with Abi in a way to separate the core of an application in small modules using rails just as a platform that uses those small modules/programs to build a real web application.
The validations of your ActiveRecord models look very convenient, because they are easy to use and have a pretty DSL. Use them is the “rails way” so you think that is what you must use. But…
Las validaciones de tus modelos de ActiveRecord
parecieran muy
convenientes, porque son muy fáciles de usar, tiene un DSL muy
entendible y rails te las pone ahí a la mano para que las uses. Pero
esto no dura para siempre.
Aunque javascript no sea el lenguaje mas placentero para trabajar, hoy en día es necesario si queremos dar una agradable experiencia al utilizar una aplicación web.
Recuerdo que de niño en la escuela de música mi maestro siempre mencionaba una frase de Arturo Sandoval (uno de los mejores trompetistas en la actualidad y de todos los tiempos) que decía: “Para tocar hay que tocar”. Siempre mencionaba esto para hacerme entender que la única forma de poder tocar bien un instrumento musical, es practicando.
Today I was working in Commentator, a gem that was extracted from Aventones, and I had a problem trying to assign a lot of configuration, variables in a class.
Maybe there is a lot of people know this solution, but before today I didn’t know it, so I want to share this =).
Imagine that you want that the home page of your app for an authenticated user, to be a Dashboard with stadistics or something special, but you want to have an informative page for the people that is not authenticated.
When I initialize a Backbone or a Javascript app, in a Rails view, I like to populate the template with the records that I am going to need. This is because if I dont populate this records in the view, then I have to fetch the record in the javascript app, so I need another call to the server :(.
Like a year ago, my style to write cucumber test was to use the cucumber’s web steps, the most I can, and the results were some tests like this one.
What you need to have an object compliant with the handler API, is to respond to the call method which receives an instance of ActionView::Template and should return a string with valid Ruby code.