Helper methods in rails are used only in views, not controllers. If you want to make a method available to multiple controllers, you can declare it in the ApplicationController, which is the base class for all your controllers. If you want the method to be visible to views, declare it as a helper_method.
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
h1 = Hash.new # => {} | |
h2 = Hash.new("a") # => {} | |
h3 = {} # => {} | |
h4 = {abc: "def"} # => {:abc=>"def"} | |
h5 = {:abc => "def"} # => {:abc=>"def"} | |
h6 = {"abc" => "def"} # => {"abc"=>"def"} | |
h1["abc"] # => nil | |
h1.fetch("abc", "kitty") # => "kitty" |
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
#Creating an app called my_great_app | |
rails new my_great_app -T -d postgresql --skip-turbolinks | |
cd my_great_app | |
git init | |
git add . | |
git commit -m "Initial commit. Rails boilerplate." | |
# Edit gemfile | |
# #Remove the reference to coffee-rails. |
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
/* | |
Prerequisite: meteor add peerlibrary:aws-sdk | |
Terminology: | |
AWS: Amazon web services | |
S3: Simple storage service (one of the above.) | |
Create a bucket on S3. Use AWS Identity and Access Manager to create | |
a user that your app can log in as . Attach a policy to that user |
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 Post < ActiveRecord::Base | |
has_many :comments, as: :commentable | |
end | |
class Photo < ActiveRecord::Base | |
has_many :comments, as: :commentable | |
end | |
class Comment < ActiveRecord::Base | |
belongs_to :commentable, polymorphic: true |
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
import UIKit | |
let nonOptionalVar: [String] = ["a", "b", "c"] | |
let optionalVar:String? = "jimmy" | |
// this compiles OK with import UIKit present | |
let ex1: [String: AnyObject] = ["key" : nonOptionalVar, "notherkey": ["content": optionalVar!]] | |
// Here we forget the ! character that unwraps the optional | |
// error: contextual type 'AnyObject' cannot be used with dictionary literal |
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
<key>NSAppTransportSecurity</key> | |
<dict> | |
<!--Include to allow all connections (DANGER)--> | |
<key>NSAllowsArbitraryLoads</key> | |
<true/> | |
</dict> |
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
# Model files | |
class Match < ActiveRecord::Base | |
belongs_to :source, foreign_key: 'from_id', class_name: Personality | |
belongs_to :target, foreign_key: 'to_id', class_name: Personality | |
end | |
class Person < ActiveRecord::Base | |
belongs_to :personality |
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
// ES 6 basics | |
setTimeout(() => { | |
console.log('Hello'); | |
console.log('Goodbye'); | |
}, 200); | |
// One - liners can omit the { } | |
// and implicitly return the value of their statement | |
setTimeout(() => 5, 200) |
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
//variables declared in global scope become properties of the window in browser environments | |
var a = 123; | |
console.log('a', window.a); | |
// functions introduce scope. A variable declared inside a function is not visible outside | |
function f() { | |
var b = 456; | |
console.log('b', b); | |
// inside the function we can still see the global a. We don't need "window." - it's implied | |
console.log('a', a); |
NewerOlder