Skip to content
Browse files

Use web controller for web interface, move data to API scope.

  • Loading branch information...
1 parent 7622a03 commit f638c3721daeecf69ae7559bd4ead06039abf32c @jimmycuadra committed Mar 11, 2012
View
1 app/assets/javascripts/application.js.coffee
@@ -29,6 +29,7 @@ window.MTNT =
# Collection
@collection = new MTNT.Collections.Entries
+ @collection.fetch()
# Navbar
@navbar = new MTNT.Views.Navbar
View
2 app/assets/javascripts/collections/entries.js.coffee
@@ -1,4 +1,4 @@
class MTNT.Collections.Entries extends Backbone.Collection
model: MTNT.Models.Entry
- url: "/entries"
+ url: "/api/entries"
View
4 app/assets/javascripts/routers/entries.js.coffee
@@ -1,6 +1,7 @@
class MTNT.Routers.Entries extends Backbone.Router
routes:
"": "index"
+ "entries": "redirect-index"
"entries/:id": "show"
index: ->
@@ -11,3 +12,6 @@ class MTNT.Routers.Entries extends Backbone.Router
model = MTNT.app.collection.get(id)
view = new MTNT.Views.Entry(model: model)
MTNT.app.display(view)
+
+ "redirect-index": ->
+ @navigate("", trigger: true, replace: true)
View
7 app/controllers/entries_controller.rb
@@ -2,12 +2,7 @@ class EntriesController < ApplicationController
respond_to :json
def index
- @entries = Entry.order("created_at ASC")
-
- respond_to do |format|
- format.html
- format.json { render json: @entries }
- end
+ respond_with Entry.order("created_at ASC")
end
def create
View
4 app/controllers/web_controller.rb
@@ -0,0 +1,4 @@
+class WebController < ApplicationController
+ def index
+ end
+end
View
5 app/views/entries/index.html.haml
@@ -1,5 +0,0 @@
-- content_for :javascript do
- :javascript
- $(function () {
- MTNT.app.collection.reset(#{@entries.to_json});
- });
View
3 app/views/web/index.html.haml
@@ -0,0 +1,3 @@
+.page-header.centered
+ %h1
+ %small Loading...
View
4 config/routes.rb
@@ -1,9 +1,9 @@
MTNT::Application.routes.draw do
mount Jasminerice::Engine => "/jasmine" unless Rails.env.production?
- constraints(format: :json) do
+ scope "api" do
resources :entries
end
- match "(*path)" => "entries#index"
+ match "(*path)" => "web#index"
end

0 comments on commit f638c37

Please sign in to comment.
Something went wrong with that request. Please try again.