This file contains 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
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. | |
This file contains 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
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 |
This file contains 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
.full-width-embedded-content | |
.twelve.piece | |
= render "tenon/tenon_content/piece_types/display/embedded_content", piece: row.pieces.first | |
.spacer |
This file contains 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
# 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) | |
This file contains 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
class NaiveMenu | |
constructor: -> | |
$(document).on('click', @hideMenu) | |
$('#menu a').on('click', @preventHide) | |
hideMenu: => | |
$('#menu').hide() | |
preventHide: (e) => | |
e.stopPropagation() |
This file contains 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
class CoolFeature | |
constructor: -> | |
$(document).on('click', '#menu a', @doACoolThing) | |
doACoolThing: (e) => | |
e.preventDefault(); | |
window.location = 'http://zombo.com' |
This file contains 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
class LessNaiveMenu | |
constructor: -> | |
$(document).on('click', @hideMenu) | |
hideMenu: (e) => | |
unless $(e.target).is('#menu *, #menu') | |
$('#menu').hide() |
This file contains 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
class QuickMoveInSearch | |
attr_accessor :params | |
def initialize(params) | |
@params = params | |
end | |
def results | |
results = scope | |
filters.each do |filter| |
This file contains 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
Test |
This file contains 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
# 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] |
OlderNewer