- Controller actions will not expose more than one instance variable
- Views are used in the context of a controller, they use instance variables
- Partials are meant to be sharable (multi controllers) so they should only use local variables
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 | |
# config/initializers/mysql_utf8mb4_fix.rb | |
require 'active_record/connection_adapters/abstract_mysql_adapter' | |
module ActiveRecord | |
module EmojiConnectionAdapters | |
refine AbstractMysqlAdapter do | |
NATIVE_DATABASE_TYPES[:string] = { name: "varchar", limit: 191 } | |
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
h = { a: nil, b: :c, c: nil } | |
result = h.keys.reduce([]) do |acc, k| | |
if h[k].nil? | |
acc << k unless acc.include? k | |
else | |
acc << h[k] | |
acc << k | |
end | |
acc |
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 Person | |
with_options if: :registration_complete? do |opts| | |
validates :zipcode, presence: true | |
validates :address1, presence:true | |
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
module KeywordAnalyzer | |
extend self | |
def analyze(comments, positive_words, negative_words) | |
positives = scan_all(comments, positive_words) | |
negatives = scan_all(comments, negative_words) | |
{ | |
positive: { | |
matches: positives, |
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
ids = Location.all.pluck(:id) | |
inserts = ids.map do |id| | |
ActiveRecord::Base.send(:sanitize_sql_array, | |
["insert into survey_requests (location_id) VALUES (?)", id]) | |
end | |
ActiveRecord::Base.connection.execute(inserts.join(";")) |
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
<entry> | |
<title>Papa John's</title> | |
<link rel="logo" type="image/jpg" href="https://print.entertainment.com/medias/sys_master/celum_assets/a2c/ebc/48c/0ac/8820935426078_C0000000000000D5.png" /> | |
<category term="P" label="AlphabetIndex" scheme="http://api.entertainment.com/AtomServer3/feeds/offers?uuid=1401914342909&location=75632&distance=25&category=25&category=146" /> | |
<category term="Dining" label="Category" scheme="http://api.entertainment.com/AtomServer3/feeds/offers?uuid=1401914342909&location=75632&distance=25&category=25&category=25" /> | |
<category term="Fast Food" label="SubCategory" scheme="http://api.entertainment.com/AtomServer3/feeds/offers?uuid=1401914342909&location=75632&distance=25&category=25&category=38" /> | |
<category term="Premium" label="OfferType" scheme="http://api.entertainment.com/AtomServer3/feeds/offers?uuid=1401914342909&location=75632&distance=25&category=25&category=470" /> | |
<author> | |
<name> |
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 SomeController < ApplicationController | |
put '/objects/:id' do |id| | |
object = Objectify.null_object(Object.find_by_id, id) #partial application method! | |
status object.status | |
object.update_attributes(params[:object]) | |
json(object, errors: object.errors) | |
end | |
end | |
class SentinelObject |
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
NUMBER_TO_GUESS = ARGV[0].to_i | |
BOUNDS = [1,1_000_000] | |
puts "The number to guess is #{NUMBER_TO_GUESS}" | |
module NumberGuesser | |
extend self | |
def guess(n1,n2) | |
(n1+n2)/2 | |
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
person.favorite_color = :green | |
person.save(some_database_save_ability) |