Ruby 轨道中的Websocket因路线而不工作
我使用websocket在rails中创建web应用程序。我在routes.rb中创建下面的添加Ruby 轨道中的Websocket因路线而不工作,ruby,ruby-on-rails-4,websocket,routes,Ruby,Ruby On Rails 4,Websocket,Routes,我使用websocket在rails中创建web应用程序。我在routes.rb中创建下面的添加 get'/:username'=>“users#profile”,如:“profile” 在此之后,我在文件中添加了以下内容 gem'websocketrails' 然后我在application.js中添加以下内容 问题是 localhost:3000/websocket===>运行配置文件_路径(获取“/:用户名”=>“用户配置文件”,如:“配置文件”) 如何解决我的websocket问题而不
get'/:username'=>“users#profile”,如:“profile”
在此之后,我在文件中添加了以下内容
gem'websocketrails'
然后我在application.js中添加以下内容
问题是
localhost:3000/websocket===>运行配置文件_路径(获取“/:用户名”=>“用户配置文件”,如:“配置文件”)
如何解决我的websocket问题而不删除{get'/:username'=>“users#profile”,如:“profile”}
我是使用web套接字开发rails的新用户。我使用路由约束修复了此问题:
get'/:hash',to:'conversations#show',约束:{hash:/((?!websocket)。)*/}
除非:hash
不包含字符串“websocket”,否则路由将无法工作
我确信有更好的正则表达式,如果我的哈希随机包含字符串“websocket”,它将失败
但是,这为我解决了开发中的问题
var dispatcher = new WebSocketRails('localhost:3000/websocket');
channel = dispatcher.subscribe('articles');
channel.bind('new', function(article) {
console.log('a new article about '+article.id+' arrived!');
})