Skip to main content

@mentions for Users with ActionText in Rails 6 Discussion

General • Asked by Chris Oliver

This is a great video.

Is it possible to remove jQuery if you are using Bootstrap 4? I know it's a dependency but maybe if you are not using all aspects of Bootstrap you can remove it.

Anyway, removing jQuery is a good way to remove 250kb (30kb gzipped) from your website's download which is not bad at all.

The next major version of Bootstrap will be without jQuery

Is it possible to change the default render for other one?

When Trix render I would like to use a different partial. For example _user_trix.html.erb so I can include some special content.

Hi Franklin,

I believe you can define a #to_trix_content_attachment_partial_path on your User model, e.g.

class User < ApplicationRecord
    include ActionText::Attachable
    def to_trix_content_attachment_partial_path

Hey Chris,

Awesome episode as usual! Few quick questions:

  1. Since ActionText is storing a global_id reference to records in order to display the updated partial at render time, does that mean it's making a separate DB query to retrieve each of those records? For instance, if I @mention 10 separate users, will it make 10 separate calls? Especially if I'm creating a commenting system that allows @mentions, and there could be 10-20 comments, each with several @mentions, etc...
  2. I notice you used Zurb Tribute for the @mention library; you've done an episode before using AtJs, any benefits to Tribute over AtJs, or just preference?

I really do like the concept of storing a reference to the partial instead of the hard-coded HTML. I'm actually in a situation where I stored the HTML snippets in the text itself and now want to change it, but am struggling with how to do that using the Froala editor. I'll eventually migrate to ActionText in a few months after Rails 6 has been vetted in the wild.

Always appreciate your timely and very applicable videos!

I will be in a similar situation and my solution will either be to cache the mention or store it in redis using the sgid and set it to auto expire in a few hours. Avatar may be out of date for a short duration because of the cache but it is a small price to pay to reduce load on the DB.

Great episode. How Trix works has become a little bit clearer. Thanks!

any way to implement @mentions if I am using rails strictly for an API?

Hi @chris I have a little app that has a venue and user that I would like the user to be able to call something like " Hey @user do you want to go to #venue on saturday?" or the like.

is that possible?

Is it possible to use ActionText in an Vue-App?

If you set a data map for the Rails path, can you replace fetch(`/mentions.json?query=${text}`) with"url")? I'm having issues with it where I get an undefined error in console.

I'm building an app that will have this feature, but I also am dealing with multi-tenancy. So how do I pass the account_id ( from multitenancy) in the fetchUsers call, here's what I have and it's not working ( I'm getting an undefined error).

initialize() {
    this.account ="account")

fetchUsers(text, callback, account) {
    let account = this.account
    .then(response => response.json())
    .then(users => callback(users))
    .catch(error => callback([]))

and in _form.html.erb

<%= f.rich_text_area :problem, placeholder: 'The raw idea, use case, something that motivates us to work on this.', data: { controller: "mentions", target: "mentions.field", mentions_account:} %>

I know the account_id is getting to the initialize method, but not the fetchUsers method. Any thoughts?

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.