spec
|--- apis #do not put into controllers folder.
|--- your_api_test_spec.rb
|--- controllers
|--- models
|--- factories
|--- views
- Assigning an object to a
belongs_toassociation does not automatically save the object. It does not save the associated object either.
- When you assign an object to a
has_oneassociation, that object is automatically saved (in order to update its foreign key). - In addition, any object being replaced is also automatically saved, because its foreign key will change too
- If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
- If the parent object (the one declaring the
has_oneassociation) is unsaved (that is,new_record?returns true) then the child objects are not saved. They will automatically when the parent object is saved.
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
| DROP TABLE IF EXISTS survey_sessions; | |
| -- Imagine a table with survey sessions | |
| -- token: some id or token to access a survey | |
| -- answers: a key value store for answers | |
| CREATE TABLE survey_sessions ( | |
| token text, | |
| answers hstore); | |
| -- We need some data to play with | |
| INSERT INTO survey_sessions (token, answers) VALUES ('9IaxxP', 'a=>1, b=>2'); |
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
| gem 'pg' | |
| group :development do | |
| gem 'ruby-debug' | |
| end | |
| gem 'rake', '~> 0.8.7' | |
| gem 'devise' | |
| gem 'oa-oauth', :require => 'omniauth/oauth' | |
| gem 'omniauth' | |
| gem 'haml' | |
| gem 'dynamic_form' |
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
| <?php | |
| /* | |
| Template Name: Landing | |
| */ | |
| // Add custom body class to the head | |
| add_filter( 'body_class', 'add_body_class' ); | |
| function add_body_class( $classes ) { | |
| $classes[] = 'landing-page'; |
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 Integer | |
| N_BYTES = [42].pack('i').size | |
| N_BITS = N_BYTES * 16 | |
| MAX = 2 ** (N_BITS - 2) - 1 | |
| MIN = -MAX - 1 | |
| end | |
| p Integer::MAX #=> 4611686018427387903 | |
| p Integer::MAX.class #=> Fixnum | |
| p (Integer::MAX + 1).class #=> Bignum |
#List of countries
It's time someone compiled a list of countries to use within a web application. This gist attempts to make a first move at that.
I've also compiled a list of nationalities
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
| .ui-autocomplete { | |
| position: absolute; | |
| top: 100%; | |
| left: 0; | |
| z-index: 1000; | |
| float: left; | |
| display: none; | |
| min-width: 160px; | |
| _width: 160px; | |
| padding: 4px 0; |