Juggernaut & Rails
辛卯[兔]年 八月初二
Juggernauthttps://github.com/maccman/juggernaut
安装配置
1. nodejs http://nodejs.org
获取 0.4.11稳定版
以下: sudo
wget http://nodejs.org/dist/node-v0.4.11.tar.gz
〉tar zxvfnode-v0.4.11.tar.gz
〉cd node-v0.4.11
〉./configure
〉make
〉make install
2. npm(需NODEJS 0.4以上版本)
以下: sudo
curl http://npmjs.org/install.sh | sh
安装模块
〉npm install socket.io
〉npm install redis
〉npm install optimist
〉npm install node-static-maccman
3. 安装并启动redis-server
〉redis-server /etc/redis/redis.conf
4. 启动 juggernaut
〉git clone https://github.com/maccman/juggernaut.git
〉cd juggernaut
〉node server.js
4. 创建RAILS应用
〉rails new juggernaut_demo
〉cd juggernaut_demo
vim Gemfile:
gem 'juggernaut'
〉bundle install
〉rails g controller welcome index publish
vim routes.rb
root :to =〉 "welcome#index"
get "welcome#publish"
vim application.html.erb
〈script src="http://localhost:8080/application.js" type="text/javascript" charset="utf-8"〉〈/script〉
vim welcome#index.html.erb
〈script type="text/javascript" charset="utf-8"〉 var jug = new Juggernaut; jug.subscribe("demo_channel", function(data){ alert(data); }); 〈/script〉
vim welcome_controller#publish
def publish
Juggernaut.publish"demo_channel", "juggernaut demo msg"
end
〉rails s
访问: http://localhost:3000/
http://localhost:3000/welcome/publish
Ok,结束。