Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit f638c3721daeecf69ae7559bd4ead06039abf32c 1 parent 7622a03
@jimmycuadra authored
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
Please sign in to comment.
Something went wrong with that request. Please try again.