Skip to content

Instantly share code, notes, and snippets.

@GerritWanderer
GerritWanderer / active_record.rb
Created October 7, 2015 11:58 — forked from jackrg/active_record.rb
Add bulk import functionality to Rails Active Record (add this file to config/initializers, call <model>.import!(array-of-record-hashes))
class ActiveRecord::Base
def self.import!(record_list)
raise ArgumentError "record_list not an Array of Hashes" unless record_list.is_a?(Array) && record_list.all? {|rec| rec.is_a? Hash }
return record_list if record_list.empty?
(1..record_list.count).step(1000).each do |start|
key_list, value_list = convert_record_list(record_list[start-1..start+999])
sql = "INSERT INTO #{self.table_name} (#{key_list.join(", ")}) VALUES #{value_list.map {|rec| "(#{rec.join(", ")})" }.join(" ,")}"
self.connection.insert_sql(sql)
@GerritWanderer
GerritWanderer / post.html
Last active August 29, 2015 14:04
Related Posts not rendered
{{#liquid-with model}}
<h1>{{title}}</h1>
<div class="col-md-9">
<img {{bind-attr src=image_big}} class="img-responsive" alt="Logo" />
<p><strong>{{teaser}}</strong></p>
<p>{{{text}}}</p>
</div>
<div class="col-md-3">
@GerritWanderer
GerritWanderer / MapsView
Created February 23, 2013 13:27
Loop over all models after content is loaded
App.MapsView = Ember.View.extend({
didInsertElement: function() {
var mapOptions = {
zoom: 12,
disableDefaultUI: true,
center: new google.maps.LatLng(52.50143, 13.402521),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
},
@GerritWanderer
GerritWanderer / error_output.rb
Created August 17, 2011 11:36
Error output when starting guard with rspec and :cli => "--drb" option
Gerrit-Wanderers-iMac:rails_template gerrit$ guard
Guard is now watching at '/Users/gerrit/Workspace/rails_template'
Starting Spork for RSpec
Using RSpec
Preloading Rails environment
Loading Spork.prefork block...
Spork is ready and listening on 8989!
Spork server for RSpec successfully started
Guard::RSpec is running, with RSpec 2!
Running all specs
jQuery(document).ajaxSend(function(event, request, settings) {
request.setRequestHeader("Accept", "text/javascript");
request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
if (settings.type.toUpperCase() == 'GET' || typeof(AUTH_TOKEN) == "undefined") return;
settings.data = settings.data || "";
// And here we're setting the authenticity_token for Rails. Of course you've actived protect_from_forgery, right?
if (typeof(AUTH_TOKEN) != "undefined") settings.data += (settings.data ? "&amp;" : "") + "authenticity_token=" + encodeURIComponent(AUTH_TOKEN);
});
<%= stylesheet_link_tag("stylesheets/#{@controller.controller_name}") if File.exist?("stylesheets/#{@controller.controller_name}.css") %>
# And If you are using SCSS, just point the path to your compiled CSS files.
# In my case I compile styesheets into /tmp/stylesheets/compiled/*.css
# This is currently the only way to get SCSS/COMPASS working on heroku.
<%= stylesheet_link_tag("compiled/#{@controller.controller_name}") if File.exist?("tmp/stylesheets/compiled/#{@controller.controller_name}.css") %>
@GerritWanderer
GerritWanderer / engine.rb
Created May 5, 2011 10:53
Change path for generated files from public to tmp directory
module Netzke
module Railz
class Engine < Rails::Engine
config.netzke = Netzke::Core::OptionsHash.new
# before loading initializers and classes (in app/**)
config.before_initialize do
Netzke::Core.config = config.netzke
Netzke::Core.ext_location = Rails.root.join("public", "extjs")
Netzke::Core.touch_location = Rails.root.join("public", "sencha-touch")