Create a Rails application to manage cinematic movie information.
- Title
- Genre
- Actor(s)
- Rating
The requirements are intentionally vague to allow some creative freedom.
# MONKEY_PATCH: Override ActiveRecord::CollectionCacheKey#collection_cache_key | |
# This allows us to preserve existing selects when paginating | |
# thus preventing errors when ordering by custom/computed select fields | |
# | |
# For the original implementation SEE: https://github.com/rails/rails/blob/5-0-4/activerecord/lib/active_record/collection_cache_key.rb | |
# IMPORTANT: Upgrade this file whenever upgrading rails versions | |
module ActiveRecord::CollectionCacheKey | |
def collection_cache_key(collection = all, timestamp_column = :updated_at) # :nodoc: | |
query_signature = Digest::MD5.hexdigest(collection.to_sql) | |
key = "#{collection.model_name.cache_key}/query-#{query_signature}" |
This is a contrived syntax comparison of CoffeeScript & TypeScript.
I know which style I prefer to write.
class ExampleJob < ApplicationJob | |
queue_as :default | |
def perform(user) | |
# do some work | |
# HACK: get around limitations in devise/warden when rendering | |
# views outside the context of a formal http request | |
renderer = ::ApplicationController.renderer.new | |
renderer_env = renderer.instance_eval { @env } |
require "benchmark" | |
require "active_support/all" | |
Benchmark.bm do |x| | |
count = 1_000_000 | |
label_size = 20 | |
x.report "check for nil:".rjust(label_size) do | |
count.times { nil && nil.length } | |
end |
// app/assets/javascripts/application.js | |
//= require jquery | |
//= require jquery-ujs | |
//= require main |
// app/assets/javascripts/modules/example.js | |
define([modules.lodash], function (_) { | |
return "This is an example."; | |
}); |
// app/assets/javascripts/main.js | |
require([modules.lodash,], function (_) { | |
console.log(_); | |
}); |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Example</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<%= stylesheet_link_tag 'application', media: 'all' %> | |
<%= csrf_meta_tags %> | |
</head> | |
<body> | |
<%= yield %> |
# app/helpers/application_helper.rb | |
module ApplicationHelper | |
def javascript_modules_tag | |
paths = Dir[ | |
Rails.root.join("app/assets/javascripts/modules/**/*"), | |
Rails.root.join("lib/assets/javascripts/modules/**/*"), | |
Rails.root.join("vendor/assets/javascripts/modules/**/*") | |
] |