Skip to content

Commit e97ea38

Browse files
committed
load messages/channels via ajax rather than inline
1 parent 0c22a49 commit e97ea38

6 files changed

Lines changed: 14 additions & 12 deletions

File tree

app/controllers/app_controller.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
class AppController < ApplicationController
22
before_filter :require_user
33
layout false
4-
5-
def index
6-
@channels = Channel.all
7-
@messages = Message.all
8-
end
94
end

app/controllers/channels_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ class ChannelsController < ApplicationController
22
before_filter :require_user
33
before_filter :find_channel, :only => [:update, :destroy]
44

5+
def index
6+
@channels = Channel.all
7+
render :json => @channels
8+
end
9+
510
def create
611
Channel.create!(params)
712
head :ok

app/controllers/messages_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
class MessagesController < ApplicationController
22
before_filter :require_user
33

4+
def index
5+
@messages = Message.all
6+
render :json => @messages
7+
end
8+
49
def create
510
message = Message.new(params)
611
message.name = current_user

app/javascripts/application.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ window.App = Spine.Controller.create({
4646
this.manager.bind("change", this.proxy(function(current){
4747
if (current == this.searches) this.sidebar.deactivate();
4848
}));
49+
50+
Message.fetch();
51+
Channel.fetch();
4952
}
5053
}).inst();
5154

app/javascripts/lib/spine.model.ajax.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var ajaxSync = function(method, record){
3535

3636
if (method == "read")
3737
params.success = function(data){
38-
(record.populate || record.load)(data);
38+
(record.refresh || record.load).call(record, data);
3939
};
4040

4141
params.error = function(e){

app/views/app/index.html.erb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
<%= csrf_meta_tag %>
77
<%= meta_tag "handle", current_user %>
88
<%= javascript_include_tag :juggernaut, "application" %>
9-
<script type="text/javascript" charset="utf-8">
10-
jQuery(function($){
11-
Message.refresh(<%=raw @messages.to_json %>);
12-
Channel.refresh(<%=raw @channels.to_json %>);
13-
});
14-
</script>
159
</head>
1610
<body>
1711
<header id="title">

0 commit comments

Comments
 (0)