Skip to content

Instantly share code, notes, and snippets.

View scottharvey's full-sized avatar

Scott Harvey scottharvey

View GitHub Profile
def update
milestone = @project.milestones.find(params[:id])
params[:milestone]['invoice_on_completion'] = "0" unless params[:milestone]['invoice_on_completion']
if milestone.update_attributes(params[:milestone])
respond_to do |format|
format.js { render :json => milestone }
end
else
MilestoneModel = Backbone.Model.extend({
initialize: function(attrs) {
this.hasMany('Tasks', 'milestone_id');
}
});
TaskModel = Backbone.Model.extend({
initialize: function(attrs) {
this.belongsTo('Milestones', 'milestone_id');
@scottharvey
scottharvey / Backbone.js has_many and belongs_to
Created April 18, 2011 05:20
This snippet allows you to define relationships between you backbone models
$.extend(Backbone.Model.prototype, {
hasMany: function(collectionName, associationColumn, opts) {
var parent = this,
associationName = (collectionName.substr(0, 1).toLowerCase() + collectionName.substr(1)),
options = $.extend({ parentId: 'id' }, opts),
collection;
this[associationName] = function() {
collection = window[collectionName].select(function(child) {
return child.get(associationColumn) == parent.get(options['parentId']);
MilestoneSet = Backbone.Collection.extend({
model: MilestoneModel,
initialize: function() {
this.bind('add', function(model) {
new ProjectView({ model: model });
});
}
});
function addWeeks(myDate, weeks) {
days = weeks * 7;
return new Date(myDate.getTime() + days*24*60*60*1000);
}
date = new Date(Date.parse('Mar 28, 2011'));
addWeeks(date, 1);
// This is returning Sun Apr 03 when it should be Mon Apr 04
render: function() {
// Initialize the template
if (this.template == null) { this.template = Haml($('#task_template').html()); }
// Update the template based on the model's attributes
$(this.el).html(this.template(this.model.viewAttributes()));
// Insert the template into the DOM if it doesn't already exist
if ($('#' + this.id).length == 0) {
$(this.model.milestone.view.el).after(this.el);
[2010-08-18 09:42:47] GEM_PATH=/Users/scott/.rvm/gems/ruby-1.8.7-p302:/Users/scott/.rvm/gems/ruby-1.8.7-p302@global GEM_HOME=/Users/scott/.rvm/gems/ruby-1.8.7-p302 BUNDLE_PATH=/Users/scott/.rvm/gems/ruby-1.8.7-p302 /Users/scott/.rvm/rubies/ruby-1.8.7-p302/bin/ruby /Users/scott/.rvm/src/rubygems-1.3.7/setup.rb
[2011-03-11 11:26:19] GEM_PATH="/Users/scott/.rvm/gems/ruby-1.8.7-p302:/Users/scott/.rvm/gems/ruby-1.8.7-p302@global:/Users/scott/.rvm/gems/ruby-1.8.7-p302@global" GEM_HOME="/Users/scott/.rvm/gems/ruby-1.8.7-p302" BUNDLE_PATH="/Users/scott/.rvm/gems/ruby-1.8.7-p302 /Users/scott/.rvm/rubies/ruby-1.8.7-p302/bin/ruby" "/Users/scott/.rvm/src/rubygems-1.3.7/setup.rb"
: line 282: /Users/scott/.rvm/src/rubygems-1.3.7/setup.rb: Permission denied
[2011-03-11 11:27:46] GEM_PATH="/Users/scott/.rvm/gems/ruby-1.8.7-p302:/Users/scott/.rvm/gems/ruby-1.8.7-p302@global:/Users/scott/.rvm/gems/ruby-1.8.7-p302@global" GEM_HOME="/Users/scott/.rvm/gems/ruby-1.8.7-p302" BUNDLE_PATH="/Users/scott/.rvm/gems/ruby-1.8.7-p302 /Us
$ rvm rubygems current
Removing old Rubygems files...
Installing rubygems dedicated to ruby-1.8.7-p302...
Installing rubygems for /Users/scott/.rvm/rubies/ruby-1.8.7-p302/bin/ruby
Error running 'GEM_PATH="/Users/scott/.rvm/gems/ruby-1.8.7-p302:/Users/scott/.rvm/gems/ruby-1.8.7-p302@global:/Users/scott/.rvm/gems/ruby-1.8.7-p302@global" GEM_HOME="/Users/scott/.rvm/gems/ruby-1.8.7-p302" BUNDLE_PATH="/Users/scott/.rvm/gems/ruby-1.8.7-p302 /Users/scott/.rvm/rubies/ruby-1.8.7-p302/bin/ruby" "/Users/scott/.rvm/src/rubygems-1.3.7/setup.rb"', please check /Users/scott/.rvm/log/ruby-1.8.7-p302/rubygems.install.error.log
Installation of rubygems did not complete successfully.
@scottharvey
scottharvey / show_terminal
Created March 10, 2011 08:07
Apple script to bring Terminal to the front then switch back to TextMate
tell application "Terminal"
activate
end tell
tell application "TextMate"
activate
end tell
@scottharvey
scottharvey / refresh_firefox
Created March 10, 2011 08:07
Apple script to refresh firefox then switch back to TextMate
tell application "Firefox"
activate
end tell
tell application "System Events"
tell process "Firefox"
keystroke "r" using {command down}
end tell
end tell