Skip to content

Instantly share code, notes, and snippets.

Rails 6
Sprockets::Rails::Helper::AssetNotPrecompiled in <new engine>
add //= link <new_engine>/application.css in the app/assets/config/manifest.js and restart the server
# app > controllers > concerns > convert_date_select_params.rb
module ConvertDateSelectParams
extend ActiveSupport::Concern
included do
before_action :convert_date
end
protected
@kt103099
kt103099 / gist:7243057
Created October 31, 2013 01:18
Douglas Crockford constructor
function constructor(init) {
var that = other_constructor(init),
member,
method = function () {
// init, member, method
};
that_method = method;
@kt103099
kt103099 / gist:3183125
Created July 26, 2012 16:40
Faraday::Error::ConnectionFailed
Omniauth Facebook Error - Faraday::Error::ConnectionFailed
Faraday::Error::ConnectionFailed
SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, '<key from fb>', '<another key from fb>'
end
class SessionsController < ApplicationController
def create
namespace :db do
desc "Load seed fixtures (from db/fixtures) into the current environment's database."
task :seed => :environment do
require 'active_record/fixtures'
Dir.glob(RAILS_ROOT + '/db/fixtures/*.yml').each do |file|
Fixtures.create_fixtures('db/fixtures', File.basename(file, '.*'))
end
end
end
# for examples of use, see...
# http://www.igvita.com/2007/03/15/block-helpers-and-dry-views-in-rails/
def block_to_partial(partial_name, options = {}, &block)
options.merge!(:body => capture(&block))
concat(render(:partial => partial_name, :locals => options), block.binding)
end
/*
* Scale all textareas dynamically on the page
* Requires Prototype
*/
Event.observe(window, 'load', function() {
$$('textarea').each(function(t){
t.scale = function (){
this.style.height = $F(this).split('\n').size() + 8 + "em";
setTimeout(function(thisObj){ thisObj.scale(); }, 1000, this);
};
# converts the number to a truncated number
# typically used for display of currency values
def smart_truncate(num)
return '--' if num.nil?
display_val = case
when num.abs > 999999: # 999,999 - round to 'X.YY M'
"%.#{2}f M" % (num / 1000000)
when num.abs > 999: # 999 - round to an integer
number_with_delimiter(number_with_precision(num, 0))