Permalink
Browse files

Figured out how to hook up nav menu active states

  • Loading branch information...
1 parent 4159d49 commit e43daaae4afb20e7e93c42cd74130919d8ae993c @bcardarella committed Jan 5, 2013
@@ -0,0 +1,7 @@
+App.ApplicationController = Ember.Controller.extend
+ isHome: (->
+ @get('currentRoute') == 'home'
+ ).property('currentRoute')
+ isUsers: (->
+ @get('currentRoute') == 'users'
+ ).property('currentRoute')
@@ -1,7 +1,8 @@
App.User = DS.Model.extend(
firstName: attr('string')
- lastName: attr('string')
- age: attr('number')
+ lastName: attr('string')
+ quote: attr('string')
+ age: attr('number')
fullName: (->
"#{@get('firstName')} #{@get('lastName')}"
).property('firstName', 'lastName')
@@ -3,11 +3,19 @@ App.Router.reopen
rootURL: '/'
App.Router.map (match) ->
- match('/').to 'index'
- match('/users').to 'users'
+ match('/').to 'home'
+ match('/users').to 'users', (match) ->
+ match('/').to 'usersIndex'
+ match('/new').to 'newUser'
+ match('/:user_id').to 'showUser'
-App.UsersRoute = Ember.Route.extend
+App.HomeRoute = Ember.Route.extend
+ setupControllers: (controller, model) ->
+ @controllerFor('application').set('currentRoute', 'home')
+
+App.UsersIndexRoute = Ember.Route.extend
model: ->
App.User.find()
setupControllers: (controller, model) ->
+ @controllerFor('application').set('currentRoute', 'users')
controller.set('users', model)
@@ -0,0 +1,23 @@
+<div class='navbar navbar-inverse navbar-fixed-top'>
+ <div class='navbar-inner'>
+ <div class='container'>
+ <div class='nav-collapse collapse'>
+ <ul class='nav'>
+ <li {{bindAttr class="isHome:active"}}>{{#linkTo 'home'}}Home{{/linkTo}}</li>
+ <li {{bindAttr class="isUsers:active"}}>{{#linkTo 'usersIndex'}}Users{{/linkTo}}</li>
+ </ul>
+ </div>
+ </div>
+ </div>
+</div>
+<div class='container' id='main'>
+ <div class='content'>
+ <div class='row'>
+ <div class='span12'>
+ <div class='page-header'>
+ {{outlet}}
+ </div>
+ </div>
+ </div>
+ </div>
+</div>
@@ -0,0 +1 @@
+<h1>Welcome!</h1>
@@ -1,3 +0,0 @@
-<h1>Welcome!</h1>
-
-{{#linkTo 'users'}}Users{{/linkTo}}
@@ -1,8 +0,0 @@
-<h1>Users</h1>
-<ul>
- {{#each users}}
- <li>{{firstName}} {{lastName}} is {{age}}</li>
- {{/each}}
-</ul>
-
-{{#linkTo 'index'}}Index{{/linkTo}}
@@ -0,0 +1,14 @@
+<h1>Users</h1>
+<table class='table table-striped'>
+ <tr>
+ <th>ID</th>
+ <th>Name</th>
+ </tr>
+ {{#each user in users}}
+ <tr>
+ <td>{{user.id}}</td>
+ <td>{{#linkTo 'showUser' user}}{{user.fullName}}{{/linkTo}}</td>
+ </tr>
+ {{/each}}
+</table>
+
@@ -0,0 +1,13 @@
+App.NavMenuView = Ember.View.extend
+ tagName: 'ul'
+ classNames: ['nav']
+ isHome: (->
+ @get('currentUrl') == '/'
+ ).property('currentUrl')
+ isUsers: (->
+ @get('currentUrl').match '/users'
+ ).property('currentUrl')
+ currentUrl: (->
+ debugger
+ window.location.pathname
+ ).property()
View
@@ -1,3 +1,3 @@
class User < ActiveRecord::Base
- attr_accessible :age, :first_name, :last_name
+ attr_accessible :age, :first_name, :last_name, :quote
end
@@ -6,24 +6,5 @@
<title>Title</title>
</head>
<body>
- <script type="text/x-handlebars">
- <div class='navbar navbar-inverse navbar-fixed-top'>
- <div class='navbar-inner'>
- <div class='container'>
- </div>
- </div>
- </div>
- <div class='container' id='main'>
- <div class='content'>
- <div class='row'>
- <div class='span12'>
- <div class='page-header'>
- {{outlet}}
- </div>
- </div>
- </div>
- </div>
- </div>
- </script>
</body>
</html>
@@ -1,8 +1,9 @@
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
- t.string :first_name
- t.string :last_name
+ t.text :quote
+ t.string :first_name
+ t.string :last_name
t.integer :age
t.timestamps
View
@@ -14,6 +14,7 @@
ActiveRecord::Schema.define(:version => 20130101211258) do
create_table "users", :force => true do |t|
+ t.text "quote"
t.string "first_name"
t.string "last_name"
t.integer "age"
View
@@ -5,3 +5,6 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
+
+User.create(:first_name => 'William', :last_name => 'Harrison', :age => 68, :quote => "I'm just singin' in the rain!")
+User.create(:first_name => 'Abraham', :last_name => 'Lincoln', :age => 56, :quote => "I'd like to see a show tonight.")
Oops, something went wrong.

0 comments on commit e43daaa

Please sign in to comment.