
正文
@mentions for Users with ActionText; 使用Tribute.js库
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
git clone从https://github.com/chentianwei411/at-mentions-with-action-text
先fork下来,然后拷贝https连接,最后在terminal上:
git clone https://github.com/chenwei/at-mentions-with-action-text.git
然后因为ruby 和 rails版本。使用命令:
rvm 2.6.1@railsXXX版本
#简单的集合命令,详细看之前的相关博客。
根据提示安装bundler和yarn更新。
10821 gem install bundler:2.0.1
10822 bundle update
10828 yarn install --check-files
最后rails db:migrate并rails s启动服务器localhost:3000
rails6.1后: Module#parent_name帮助方法被替换:
# config.application_name = Rails.application.class.parent_name
config.application_name = Rails.application.class.module_parent_name
实做@mention功能
使用tribute库来实现@mention功能,支持Vue。
参考https://zurb.github.io/tribute/example/案例,在输入框输入@可以显示人名的下拉列表。
trix文本编辑器已经被集成到新版本。
使用stimulus.js增加JavaScript脚本。
rails webpacker:install:stimulus
然后下载ZURB tribute javascript library。这里使用yarn,也可以用gem 'tribute'
https://github.com/zurb/tribute
这是用ES6写的@mention引擎。无需依赖dependencies。跨浏览器。
yarn add tributejs
按照路径->controller->view思路:
routes.rb内添加:
resources :mentions, only: [:index]
目的是点击这个url来自动获取users。然后就可以动态地load. json格式的user数据。







