This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.AlbumItemView = Backbone.View.extend | |
tagName: 'li' | |
template: _.template "<a href='/users/<%= user_id %>/albums/<%= id %>'><%= title %></a><button class='unfeature'>Unfeature ×</button>" | |
render: -> | |
@$el.html @template @model.attributes | |
this | |
events: | |
'click .unfeature': 'unfeature' | |
unfeature: -> | |
@model.save(featured: false) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1] pry(main)> Album.where(title: 'A Love Supreme').first | |
Album Load (2.1ms) SELECT "albums".* FROM "albums" WHERE "albums"."title" = 'A Love Supreme' ORDER BY "albums"."id" ASC LIMIT 1 | |
=> #<Album id: 1, artist: "John Coltrane", title: "A Love Supreme", year: 1965, song_count: 3, user_id: 2, created_at: "2014-11-29 23:21:16", updated_at: "2014-12-08 15:23:54", featured: false> | |
[2] pry(main)> Album.where(title: 'A Love Supreme').first.update_attribute(:featured, true) | |
Album Load (0.5ms) SELECT "albums".* FROM "albums" WHERE "albums"."title" = 'A Love Supreme' ORDER BY "albums"."id" ASC LIMIT 1 | |
(0.1ms) BEGIN | |
SQL (0.3ms) UPDATE "albums" SET "featured" = $1, "updated_at" = $2 WHERE "albums"."id" = 1 [["featured", "t"], ["updated_at", "2014-12-15 15:46:19.646739"]] | |
(1.0ms) COMMIT | |
=> true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
± % rails c | |
Loading development environment (Rails 4.1.0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var album = App.albums.findWhere({ title: 'A Love Supreme' }); | |
album.get('featured'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.AlbumItemView = Backbone.View.extend | |
tagName: 'li' | |
template: _.template "<a href='/users/<%= user_id %>/albums/<%= id %>'><%= title %></a><button class='unfeature'>Unfeature ×</button>" | |
render: -> | |
@$el.html @template @model.attributes | |
this | |
events: | |
'click .unfeature': 'unfeature' | |
unfeature: -> | |
@model.save(featured: false) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var album = App.albums.findWhere({ title: 'A Love Supreme' }); | |
console.log(album.get('featured')); | |
// true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var album = App.albums.findWhere({ title: 'A Love Supreme' }); | |
// undefined | |
album.attributes | |
// Object {id: 1, artist: "John Coltrane", title: "A Love Supreme", year: 1965, song_count: 3…} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.AlbumItemView = Backbone.View.extend | |
… | |
unfeature: -> | |
@model.set(featured: false) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.Views.AlbumsListView = Backbone.View.extend | |
… | |
itemView = new App.Views.AlbumItemView(model: model) | |
… |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.AlbumItemView = Backbone.View.extend | |
tagName: 'li' | |
template: _.template "<a href='/users/<%= user_id %>/albums/<%= id %>'><%= title %></a><button class='unfeature'>Unfeature ×</button>" | |
render: -> | |
@$el.html @template @model.attributes | |
this | |
events: | |
'click .unfeature': 'unfeature' | |
unfeature: -> | |
console.log 'clicked' |