Skip to content

Instantly share code, notes, and snippets.

View SeanRoberts's full-sized avatar

Sean Roberts SeanRoberts

View GitHub Profile
Ruby/Rails
- Use latest stack (Ruby 2.1.x, Rails 4.x, Postgresql)
- Prefer the new hash syntax, but use the old one when necessary (ie. when you need to use strings as keys)
- Code in ActiveRecord models should pertain directly to storing or retrieving data
- Use Draper to decorate model instances and test your decorators with RSpec (app/decorators is the place for this)
- Put business logic into service classes and test them with RSpec (app/services is a fine place for this, you can get more specific if your services folder gets fat)
- I like to name my service classes after what they do, or give them cute names occasionally (AddsProductstoCart or CartStuffer)
- Don’t hesitate to namespace related models or services into modules.
- Use Resque and Redis for background job handling.
describe Classname do
describe '#a_method' do
context 'when a thing' do
it 'should do a thing' do
#
end
end
context 'when a different situation' do
it 'should do something different' do
.full-width-embedded-content
.twelve.piece
= render "tenon/tenon_content/piece_types/display/embedded_content", piece: row.pieces.first
.spacer
# Often you will want to have behaviour where clicking outside of a certain element will close it,
# for example, maybe you have a menu and you want to close it when the user clicks outside of it.
# In that case what you need to do isn't so much capture a click outside of element as it is
# capture a click anywhere and then stop the closure if it's in the menu, I've been doing it like this:
class DumbMenu
constructor: ->
$(document).on('click', @hideMenu)
$('#menu a').on('click', @preventHide)
class NaiveMenu
constructor: ->
$(document).on('click', @hideMenu)
$('#menu a').on('click', @preventHide)
hideMenu: =>
$('#menu').hide()
preventHide: (e) =>
e.stopPropagation()
class CoolFeature
constructor: ->
$(document).on('click', '#menu a', @doACoolThing)
doACoolThing: (e) =>
e.preventDefault();
window.location = 'http://zombo.com'
class LessNaiveMenu
constructor: ->
$(document).on('click', @hideMenu)
hideMenu: (e) =>
unless $(e.target).is('#menu *, #menu')
$('#menu').hide()
class QuickMoveInSearch
attr_accessor :params
def initialize(params)
@params = params
end
def results
results = scope
filters.each do |filter|
# Consider the following model
# This will not actually save history for the description.
class Event
has_history
tenon_content :description
end
# However, making it save the description is real easy:
class Event
has_history includes: [:description_tenon_content_rows]