See also questions close to this topic

My rails 5 form is automatically submitting when the user changes the option in collection_select. There are two parameters on that page, so that the user can change either, they need to use the select button.

into controllers/private/messages_controller.rb and it seems to work, but I want to use exact same method in another controller so, it would be better if I'll manage to use it with ActiveSupport::Concern

From the RabbitMQ docs, a message is received asynchronously using @RabbitListener endpoint:

"The easiest way to receive a message asynchronously is to use the annotated listener endpoint infrastructure. In a nutshell, it allows you to expose a method of a managed bean as a Rabbit listener endpoint."

What does receiving asynchronously mean here exactly? What is the effect of using blocking calls, e.g. synchronous HTTP inside of the processOrder(...) function above, given the definition of receiving asynchronously?

In Ahoy for Rails, I want to track additional data that is derived from a Visit's existing data. The documentation suggests overriding the track_visit method.

However, the Visit data I need to use is the geocoding data, which does not seem to be present (yet) when track_visit is executed.

Specifically, I've added a column world_region_id to my Visits table that corresponds to a WorldRegion model in my app. I want to take the Visit.country string and map it to the corresponding WorldRegion. However, the following code always leaves world_region_id to be nil:

(.find_by_alias takes any country name string, including common variations, to allow for various geocoding sources, e.g. "United Kingdom" and "Great Britain" would map back to the same WorldCountry.)

Executing super first, then setting data[:world_region_id], results in the same.

The geocoding itself works fine, i.e. when I check the respective Visit in the database, country etc. will be set, but world_region_id will be nil. The way I derive the world_region_id also works when I replace data[:country] with a string.

So it seems the issue lies in the order of execution. Where or how should I add the logic so that I can successfully use Visit.country?