This file contains hidden or 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 Item < ActiveRecord::Base | |
| end |
This file contains hidden or 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
| group :development do | |
| gem 'guard' | |
| gem 'guard-minitest' | |
| gem 'terminal-notifier-guard' | |
| end |
This file contains hidden or 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 ItemsController < ApplicationController | |
| def create | |
| @item = Item.create!(item_params) | |
| render json: @item | |
| end | |
| private | |
| def item_params | |
| params.require(:item).permit(:name) |
This file contains hidden or 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
| scope :today, ->{ where('DATE(created_at) = ?', Date.today } # MySQL | |
| scope :today, ->{ where('created_at::date = ?', Date.today } # PostgreSQL | |
| Item.where(created_at: 5.days.ago..Date.today) | |
This file contains hidden or 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
| def link_to_next(article) | |
| target = article.next || Article.new(date: Date.today) | |
| link_to "next", target.today? ? root_path : target | |
| end | |
| # do not initialize an Article | |
| def link_to_next(article) | |
| target = article.next | |
| link_to "next", target.try('!today?') ? target : root_path |
This file contains hidden or 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
| City = | |
| find: (location) -> | |
| promise = $.Deferred() | |
| $.ajax '/cities', | |
| data: q: location | |
| success: (result) -> | |
| promise.resolve result.city | |
| error: -> | |
| promise.reject 'invalid location' | |
| promise |
This file contains hidden or 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
| require 'test_helper' | |
| class ArticleTest < ActiveSupport::TestCase | |
| test 'tested_class is Article' do | |
| assert_same Article, tested_class | |
| end | |
| private | |
| def tested_class |
This file contains hidden or 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
| set nonumber | |
| set relativenumber | |
| function! ToggleNumber() | |
| if &relativenumber | |
| set number | |
| set norelativenumber | |
| else | |
| set nonumber | |
| set relativenumber |
This file contains hidden or 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
| # TL;DR | |
| # verb(action, *args) | |
| # verb(action, parameters, session, flash) | |
| require 'test_helper' | |
| class ProjectsControllerTest < ActionController::TestCase | |
| setup do |
This file contains hidden or 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 Club < ActiveRecord::Base | |
| def self.center | |
| @center ||= south_west.zip(north_east).map do |a| | |
| (a[0] + a[1]) / 2 | |
| end | |
| end | |
| def self.south_west | |
| @south_west ||= [minimum(:lat), minimum(:lng)] | |
| end |