Ask A Question


You’re not receiving notifications from this thread.

Screencast requests: Global ID and @mentions

Marc Köhlbrugge asked in Site Feedback

After watching the recent screencast on Action Text and @mentions, I became curious as to how Rails stores references to these associations in texts. Turns out it uses something called Global ID:

This might be an interesting topic for a future screencast.

Let's say you're building a Twitter-like app and want to support @mentions in the tweets. However, unlike Twitter you actually want the mentions to remain working after a mentioned user changes their username. We don't need the full rich text feature set, but similarly to Action Text we would store the actual user ID (or more specifically the Global ID) and render out the correct username whenever the tweet is shown.

We could create an additional Mention record as well, so we have an easy way to query in which tweets a particular user was mentioned

What do you think? I think the current @mentions screencasts are nice, but rather restricted in real-world applicability. I've been looking for a good approach and Global ID seems like the way to go.


Hey Marc!

Not sure if you missed it in the episode but thats exactly how ActionText works. It uses signed global IDs to load models and it does all that automatically for you so theres nothing you need to build.

To query, you would probably need to make an adjustment since the signed global id does not have a readable value stored in the db. May just want to add a join table between the models and add references during save.


I watched the episode, but the Global ID stuff all happens behind the scenes. I figured it would be interesting to take a closer look at how it works so we can implement something similar in situations where ActionText is overkill.


I gotcha! Sorry, I wasn't sure what you were getting at.

In that case, I should note that ActionText is pretty simple behind the scenes. If you were to implement your own thing, you'd end up building like 90% of ActionText. I don't think you'd get any benefit from doign that.

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 83,453+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.