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
# config/routes.rb | |
# "Cast a Vote"-Workflow | |
get 'vote', to: 'cast_votes#get_voter_token', as: :new_vote | |
post 'vote', to: 'cast_votes#verify_voter_token' | |
get 'cast_vote', to: 'cast_votes#get_choices', as: :cast_vote | |
post 'cast_vote', to: 'cast_votes#cast_vote' | |
get 'thank_you', to: 'cast_votes#thank_you', as: :thank_you | |
class CastVotesController < ApplicationController |
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
Planning the database structure for go.vote | |
# Model structure | |
The main models are: | |
- Election | |
- Candidate | |
- Voter | |
- Vote | |
The models are associated as follows: |
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
UPDATE media_images | |
SET collectively_manage_publication_for_all_locales = ( | |
CASE | |
WHEN ((published_de = published_en) AND (published_from_de = published_from_en)) | |
THEN TRUE | |
ELSE FALSE | |
END | |
) |
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
require 'active_support/core_ext' | |
def calendar_week(week) | |
now = Date.current | |
year = now.cweek < week ? now.year : now.year + 1 | |
Date.commercial(year, week, 1) | |
end | |
p calendar_week(49) | |
# => Mon, 02 Dec 2013 |
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
form | |
.field | |
@extend .form-group | |
input[type=text], textarea, input[type=email], input[type=search], input[type=password] | |
@extend .form-control | |
label | |
@extend .control-label | |
.field .field_with_errors | |
@extend .has-error |
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
// Formtastic stylesheet based on the gem's version, retrieved 2013-01-04 | |
// This version reflects the gem exactly. | |
// Use as a base for modifications. | |
.formtastic | |
margin: 0 | |
padding: 0 | |
// resets | |
ul, ol, li, fieldset, legend, input, button, textarea, select, p |
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
## | |
# A ruby-powered table of contents layout | |
words = %w(we are the world lets make it a better place we are the world) | |
words.each_with_index {|word, page| puts word.ljust(10, '.') + (page*page).to_s.rjust(3, '.')} | |
# => Output | |
# we..........0 | |
# are.........1 |
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 Range | |
def end_at(x) | |
Range.new(self.begin, x) | |
end | |
def start_at(x) | |
Range.new(x, self.end) | |
end | |
end |
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
## | |
# Array of arrays to hash conversion | |
# | |
## | |
# Version 1 | |
array = [[1, 1], [2, 2], [3, 3]] | |
hash = Hash[*array.flatten] |
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
# encoding: utf-8 | |
require 'talks' | |
class Hash | |
## | |
# Cascading Fetch | |
# | |
# Tries to fetch provided symbols one after the other | |
# and return fallback non-symbol value otherwise |