Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View scottmessinger's full-sized avatar

Scott Ames-Messinger scottmessinger

View GitHub Profile
-semantic_form_for @presenter.sequence, :action => 'update', :html => {:id => 'edit_narrative'} do |s|
-s.semantic_fields_for :unit, :index => nil do |u|
-u.inputs do
=u.input :narrative_sidebar, :label => false,:as => :text, :input_html => {:class => 'mceEditorNarrative'}, :wrapper_html => { :id => 'narrative_sidebar'}
=u.input :narrative, :label => false, :input_html => {:class => 'mceEditorNarrative'}, :as => :text, :wrapper_html => {:id => 'main_narrative'}
=u.input :narrative_sidebar_flag, :as => :boolean, :label => "Enable Sidebar:", :wrapper_html => {:class => 'enable_narrative_sidebar'}, :input_html => {:type => "checkbox"}
-s.buttons do
=s.commit_button :label => 'Update'
@scottmessinger
scottmessinger / WTF.js
Created February 21, 2011 02:08
I don't understand.
// This doesn't work:
> var data = $.ajax({ url : '/plans.json'}).responseText
> undefined
// However, if I set data then ask for the responseText, it does. I don't understand why this happens, but I accept it.
> var data = $.ajax({ url : '/plans.json'})
> undefined
> data.responseText
> "[{"plan":{"created_at":"2011-02-21T00:36:29Z","id":1,"updated_at":"2011-02-21T00:36:29Z"}},{"plan":{"created_at":"2011-02- etc etc......
Hi Tom and Yehuda,
I like html. I like handlebars. I don't like what Sproutcore does with handlebars. In the example below, it appears that Sproutcore modifies #each to automatically insert li tags. I find this aggravating. I want Sproutcore to handle my data, DOM updates, etc and let me worry about markup. By their nature, helper methods are not transparent and make it difficult for designers to mark up a page for a SC app.
I like using data-attr because they respect MY markup. I can get behind handlebars in SC if it can also respect my markup.
Thanks for dialoging about this. I really want to use SC...I just can't get over the view complexity at this point.
Thanks!
Scott
@scottmessinger
scottmessinger / gist:1018177
Created June 10, 2011 03:15
Model has no method '_configure'
Relevant Code:::
var Course = Backbone.Model.extend({
url : function(){
var base = 'courses'
if (this.isNew()) return base;
return base + (base.charAt(base.length-1) == '/'?'' : '/') + this.id;
}
})
@scottmessinger
scottmessinger / My_model.js
Created June 30, 2011 01:49
Backbone's Extend Method
var Unit = Honeybee.Model.extend(
{
toJSON : function(){
var copy = ko.toJS(this)
return {title : copy.title}
}
,initialize: function(data){
_.extend( this, ko.mapping.fromJS( data, unitMappings, this ) ,
@scottmessinger
scottmessinger / courses_controller.rb
Created July 13, 2011 16:39
Devise in namespaces
class Api::V1::CoursesController < ApplicationController
def create
current_user ## is nil even though there's a user logged in. How do I access current_user?
end
end
@scottmessinger
scottmessinger / gist:1106734
Created July 26, 2011 13:19
Just snipped so I can copy/paste with syntax highlighting for e-mail thread posts...
<ol data-bind="template :{name : 'show_unit', foreach: unit().units , sortableList: unit().units}">
<span data-bind="text: $item.index"></span>
// The backbone router process the url and then calls a function. Here's one of the functions.
// NOTE: Unit.fetch, Course.fetch, Unit.fetch methods are all functions which take params, makes an ajax call, then takes the data and creates a new model and returns it. E.g. $.ajax({...}, function(){ new User(data) })
,show_unit: function(username, course_slug, id){
User.fetch(current_user.username, function(user){
App.VMs.current_user(user)
Course.fetch(username, course_slug, function(course){
App.VMs.course(course)
Unit.fetch(options, function(unit){
@scottmessinger
scottmessinger / code.js
Created July 26, 2011 16:12
Manual subscriptions in Knockout.js
// Unit.fetch makes an ajax call and passes new Unit(data) to the callback.
Unit.fetch(options, function(unit){
addFunctions(unit)
App.VMs.unit(unit)
}
// the console never logs "subscribed"
var addFunctions = function(viewModel){
viewModel.units.subscribe(function(){
console.log("subscribed")
@scottmessinger
scottmessinger / walkthrough.js
Created July 27, 2011 17:26
Common Curriculum Knockout.js Walkthrough
// index.haml
$(function() {
App.init();
});
//application.js
var App = {
VMs : {
global : {
mainTemplate : ko.observable()