Ask A Question

Notifications

You’re not receiving notifications from this thread.

@Mentions, Autocomplete, Notifications, and Links | GoRails - GoRails

Chris Oliver asked in General

This is cool. Although, when you said 'notifications' I was expecting in-app notifications not an email notification. I was wondering how you were going to cover so much material in 1 episode, but now that I realize it was just a brief email notification, I understand.

I would modify the title and description to just focus on @Mentions and Autocomplete, with a sprinkle of notifications and links added in.

Otherwise, awesome stuff.

Reply

In-app notifications is actually going to be my next episode!

Reply

Chris, great stuff, thanks. Note that \w in a regex *is* a character class, so it does not need to be enclosed in the [ ] brackets if it's by itself. So /@(\w+)/ is all you need. Also, this would need some tweaking to avoid matching the domain name of an email address, for example. (html-pipeline's version does this)

Reply

Great points! Upvoting so everyone can see this. :)

Reply

Great episode! Learn few tricks there.

I'm not is there any way to use At.js to support what is similar to facebook mention, it means it will use display name instead of unique field, but I think they keep either id or username in local values there.

Reply

You might be able to, I'm not entirely sure. The full names make it more complicated.

You can inspect the HTML on Facebook to get an idea of how they do it. They have a much more complex system for it as you'll see with their "highlighter" class right above the textarea. Rather that doing much of this in text, they handle much of it in the JS instead so they can do more complex things. An out-of-the-box JS library like at.js won't be able to compete with that.

Reply

it is an awesome and great episode, thanks so much

Reply

Thanks David! :)

Reply

I found a gotcha to be aware for everyone who is/were watching this episode. When upon calling @mention into the post and click on the referenced username, it will return a invalid number ID instead of the username ID.

I made some changes to the User controller ruby code. To get your username referenced in the URL like /users/yourusernamehere, you will need to the following changes:

In your db/migrate/[datetime-stamp]_create_users.rb:

line 4: create_table :user, id: false do # add this id method into your file before migrating

In app/models/user.rb:

[new line] line 2: self.primary = 'username'

In config/routes.rb:

resources :users, param: :username # add this line as well.

In app/controllers/users_controller.rb:

def user_params
User.find(params[:username]) # alter :id with username
end

And that should work for everyone! (p.s: you will need to reset your database if you migrated before aka rake db:reset)

Reply

Super awesome! Thanks for this. :)

Reply

How to apply complete name as mention and link so it can have space etc?

Reply
masud hossain masud hossain

Great video!

Reply

hi @excid3:disqus on the @mentions episode can you share the css you use to show both user name and profile picture?

Thanks

Reply

Hey Chris,I don't have a Users Controller.I am using devise so i have a registrations controller
class RegistrationsController < Devise::RegistrationsController
private

def sign_up_params
params.require(:user).permit(:email, :user_name, :full_name, :password, :password_confirmation)
end

def account_update_params
params.require(:user).permit(:email, :user_name, :password, :password_confirmation, :current_password)
end
end

I added an index action and created an index.json.builder but when i navigate to /registrations.json i get an error

So how do i get json file.

Reply

You can still create a users controller even if you use Devise so you can make the /users.json endpoint. Devise doesn't define a GET route for /users, just POST and PUT which means you're free to create one or you can make a different route as well.

Reply
Join the discussion
Create an account Log in

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

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

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

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2024 GoRails, LLC. All rights reserved.