Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Pusher試用

  • Loading branch information...
commit ee4a6a70e57569d351fca4f65228ccd9dbe1d0e5 1 parent dd4b81c
shu_0115 authored Shun Matsumoto committed
View
2  Gemfile
@@ -54,3 +54,5 @@ group :development do
gem 'custom-template'
end
+# For Pusher
+gem 'pusher'
View
5 Gemfile.lock
@@ -93,6 +93,9 @@ GEM
omniauth-oauth (~> 1.0)
pg (0.13.2)
polyglot (0.3.3)
+ pusher (0.9.3)
+ multi_json (~> 1.0)
+ signature (~> 0.1.2)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
@@ -123,6 +126,7 @@ GEM
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
+ signature (0.1.3)
simple_oauth (0.1.8)
sprockets (2.1.3)
hike (~> 1.2)
@@ -159,6 +163,7 @@ DEPENDENCIES
omniauth-scaffold
omniauth-twitter
pg
+ pusher
rails (= 3.2.3)
sass-rails (~> 3.2.3)
sqlite3
View
7 app/controllers/top_controller.rb
@@ -53,4 +53,11 @@ def create
render action: "index" and return
end
+ #------#
+ # chat #
+ #------#
+ def chat
+ Pusher['test_channel'].trigger( 'test_event', { test_text: params[:text] } )
+ end
+
end
View
4 app/views/layouts/application.html.erb
@@ -19,6 +19,7 @@
//-->
</script>
</head>
+
<body>
<%# ----- 追加 ----- %>
@@ -26,7 +27,8 @@
<%# ログイン済み %>
<%= link_to_unless( current_user.screen_name.blank?, image_tag( current_user.image, size: "20x20" ), "https://twitter.com/#!/#{current_user.screen_name}", target: "_blank" ) %>
<%= current_user.name %>
- | <%= link_to "Logout" , logout_path %>
+ | <%= link_to( "Chat", { controller: "top", action: "chat" } ) %>
+ | <%= link_to "Logout", logout_path %>
<% else %>
<%# 未ログイン %>
<%#= link_to "Login", "/auth/#{DEFAULT_PROVIDER}" %>
View
15 app/views/top/chat.html.erb
@@ -0,0 +1,15 @@
+<script src="http://js.pusher.com/1.11/pusher.min.js"></script>
+<script type="text/javascript">
+ var pusher = new Pusher('<%= Pusher.key %>'); // uses your API KEY
+ var channel = pusher.subscribe('test_channel');
+
+ channel.bind( 'test_event', function(data){
+ document.getElementById('get_text').innerText = data.test_text;
+ } );
+</script>
+
+<br /><br />
+
+<span id="get_text">TEST</span><br />
+
+<br /><br />
View
7 config/environments/development.rb
@@ -35,4 +35,11 @@
# Expands the lines which load the assets
# config.assets.debug = true
config.assets.debug = false
+
+ # For Pusher
+ require 'pusher'
+
+ Pusher.app_id = '20717'
+ Pusher.key = '2558740a1983a75d573a'
+ Pusher.secret = 'c18a10d99f6f5ff6c8a4'
end
View
2  config/routes.rb
@@ -4,7 +4,7 @@
match "/auth/:provider/callback" => "sessions#callback"
match "/auth/failure" => "sessions#failure"
match "/logout" => "sessions#destroy", :as => :logout
-
+
# Sample of regular route:
# match 'products/:id' => 'catalog#view'
# Keep in mind you can assign values other than :controller and :action
Please sign in to comment.
Something went wrong with that request. Please try again.