Skip to content

Instantly share code, notes, and snippets.

@majornorth
majornorth / edit.html.erb
Created June 15, 2013 17:27
The problem I was having was that the activity ID wasn't being received by the controller method. In params, I had [:activity] and not [:user]. Basically, the form and controller are adding a record to the join table for activities_users, submitting an ID for both activity_id and user_id. I got the help of my roommate, who is a programmer, and n…
<h2>Favorite Activities</h2>
<ul>
<% User.find(current_user.id).activities.each do |a| %>
<li><%= a.name %>
<%= form_for @user, :url => removefavorite_path do |f| %>
<%= f.hidden_field :activity_id, :value => a.id %>
<%= f.submit('Remove') %>
<% end %>
</li>
<% end %>
@majornorth
majornorth / event.rb
Last active December 18, 2015 19:48
I need to figure out a way to save :status (an attribute of the event model) if it meets the condition and is set to "full". I tried using @event.update_attributes(params[:status]), but that didn't work. I've also tried @status.save and just save, but those result in "undefined method errors". Suggestions?
class Event < ActiveRecord::Base
attr_accessible :needed, :start, :location, :league, :skill_level, :field_type, :organizer, :note, :status
has_and_belongs_to_many :users
end
@majornorth
majornorth / devel.html
Created March 25, 2014 04:43
Game detail conditionals
<template name="soloGameSummary">
<div class="game-summary">
{{#if organizing}}
<strong class="text-{{#if past startsAt}}muted{{else}}info{{/if}}">
{{participle startsAt past='Organized' present='Organizing'}}
</strong>
{{else}}
{{#if playing}}
<strong class="text-{{#if past startsAt}}muted{{else}}info{{/if}}">
{{participle startsAt past='Played' present='Playing'}}
@majornorth
majornorth / script
Created May 9, 2014 22:28
Codecademy:JavaScript::Search Text for Your Name (5/7)
/*jshint multistr:true */
var text = "Stewart containing some text for Stewart written and developed by Stewart";
var myName = "Stewart";
var hits = [];
/* assign the value of 0 to i and continue to the loop while i is less than the length of the variable 'text', and add 1 to i after executing the code block */
for (i = 0; i < text.length + 1; i++) {
<template name="favoriteGames">
<header class="bar bar-nav">
<i class="icon-cancel pull-left header">
</i>
<button class="btn btn-link btn-nav pull-left header cancel-improve" id="cancelImprove">
Cancel
</button>
<h1 class="title header">Favorite games</h1>
</header>
<div class="content">
@majornorth
majornorth / _box_template.html
Last active August 29, 2015 14:07
Phrasebank tooltip
{% if is_tutor or is_superuser %}
<span id="phrasebank-tooltip" class="open-phrasebank insert"
data-title="Easily insert saved phrases. Use presets or create custom phrases to quickly answer student questions."
data-placement="right"
data-name="lesson-help-bubble-chat"
data-trigger="manual"></span>
{% endif %}
toggle: function() {
if (this.isExpanded()) {
this.minimize();
if (show === true) {
this.isVisible = true;
$("#phrasebank-tooltip").tooltip("show");
} else {
this.isVisible = false;
$("#phrasebank-tooltip").tooltip("hide");
<div class="written-lesson-modal hidden">
<div class="modal-header">
<h3>Request a Written Lesson</h3>
</div>
<div class="modal-body">
<form id="new-proposal" class="proposal-form form-horizontal" method="POST" action="">
{% load tags %}
{% csrf_token %}
{% if is_parent or is_tutor %}
<div class="control-group">
@majornorth
majornorth / views.js
Last active August 29, 2015 14:16
My first Backbone feature
// Before
var ExplanationReviewForm = Backbone.View.extend({
ENDPOINTS: {},
$form: null,
submitted: false,
positiveReview: false,
events: {
'click .thumbs-up': 'submitPositiveReview',
var VenuesView = Backbone.View.extend({
tagName: "ul",
id: "venues",
initialize: function(options){
this.bus = options.bus;
},
render: function(){