Skip to content

Instantly share code, notes, and snippets.

View mikecmpbll's full-sized avatar
🎯
Focusing

Mike Campbell mikecmpbll

🎯
Focusing
  • Skipton, North Yorkshire
View GitHub Profile
@mikecmpbll
mikecmpbll / gist:5575550
Last active December 17, 2015 07:49
Rails Engine view paths
Missing template layouts/application with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/Users/mike.campbell/projects/engines/myengine_shell/app/views" * "/Users/mike.campbell/projects/engines/myengine/app/views"
# Myengine is the engine, and MyengineShell is an app which mounts it.
# When I create the engine it generates an application.html.erb layout file in app/views/layouts/myengine/application.html.erb.
# How come my app can't find the layout?
# app/decorators/models/my_engine/user_decorator.rb
MyEngine::User.class_eval do
def self.find_by_name str
where("CONCAT(#{table_name}.firstname, ' ', #{table_name}.surname) LIKE :s", { s: "%#{str}%" })
end
end
# rails c
MyEngine::User.find_by_name "John"
@mikecmpbll
mikecmpbll / app.js
Created May 31, 2013 11:07
Renders the collection twice.
define([
'jquery',
'underscore',
'backbone',
'views/request',
'views/new_request'
], function($, _, Backbone, RequestView, NewRequestView){
var AppView = Backbone.View.extend({
el: $("#request-app"),
events: {
class Task < ActiveRecord::Base
def self.todays_tasks
where(due_date: Date.today.beginning_of_day..Date.today.end_of_day)
end
def self.tomorrows_tasks
where(due_date: Date.tomorrow.beginning_of_day..Date.tomorrow.end_of_day)
end
end
UNITS_IN_MS = {
0 => 3600000, #hour
1 => 60000, #minute
2 => 1000 #second
}
time = "00:00:33.55"
ms = time.split(":").each_with_index.map{|d, i| d.to_f*UNITS_IN_MS[i]}.reduce(:+).to_i
=> 33550
class Client < ActiveRecord::Base
def to_param
slug
end
end
@mikecmpbll
mikecmpbll / rails_error.rb
Last active December 25, 2015 04:59
has_and_belongs_to_many association with scope not joining correct table in scope.
unless File.exists?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
unless File.exists?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
<body id="brands" data-hook="body">
<ul class="letters">
<% ('A'..'Z').each do |letter| %>
<li><%= link_to letter, "#", class: "key-link", data: { letter: letter } %></li>
<% end %>
</ul>
<hr>
<% @brands.each do |key, brands| %>
<ul class="brand-letters">
<li id="letter-<%= key %>" class="key"><%= key %></li>
module Plugin1
def some_method
puts "ha!"
end
end
module Plugin2
def some_method_again
puts "hrn..."
end