Skip to content

Instantly share code, notes, and snippets.

View tubbo's full-sized avatar
:shipit:
i don't make rails apps you use, i make the rails apps you use faster..

Tom Scott tubbo

:shipit:
i don't make rails apps you use, i make the rails apps you use faster..
View GitHub Profile
@tubbo
tubbo / README.md
Last active December 20, 2015 13:08 — forked from Fire-Dragon-DoL/README.md

What would I like to do

cat = Cat.create(name: 'lorem')
cat.cat_color = CatColor.new(name: 'Red')

cat.save!

I would like to have cat_color instance automatically saved (after validation). How to achieve this?

@tubbo
tubbo / article.rb
Created August 22, 2013 20:44 — forked from cored/article.rb
new_article.comments << (comments + article_to_merge.comments).map do |comment|
comment.article = new_article
comment
end
article_to_merge.destroy
destroy
@tubbo
tubbo / billing_controller.rb
Last active December 22, 2015 07:28
THE WORNG WAY OMGHGHGMGHGHG
class BillingController < ApplicationController
def index
# NOTHING MUAHAHAAHAHAHAHAHHAHAA A
end
end
<fieldset>
<%= f.text_field :university, placeholder: "#{t(:university, scope: 'activerecord.attributes.educational_experiences')}" %>
<%= f.text_field :major, placeholder: "#{t(:major, scope: 'activerecord.attributes.educational_experiences')}" %>
<%= f.text_field :minor, placeholder: "#{t(:minor, scope: 'activerecord.attributes.educational_experiences')}" %>
<%= f.hidden_field :_destroy %>
<%= link_to "[remove]", "#", class: "remove_fields" %>
</fieldset>
<fieldset>
<%= f.text_field :university, placeholder: "#{t(:university, scope: 'activerecord.attributes.educational_experiences')}" %>
<%= f.text_field :major, value: f.object.major placeholder: "#{t(:major, scope: 'activerecord.attributes.educational_experiences')}" %>
<%= f.text_field :minor, value: f.object.minor placeholder: "#{t(:minor, scope: 'activerecord.attributes.educational_experiences')}" %>
<% unless f.object.new_record? %>
<%= f.hidden_field :_destroy %>
<%= link_to "[remove]", "#", class: "remove_fields" %>
<% end %>
</fieldset>
@tubbo
tubbo / 1error
Created September 24, 2013 20:25
NoMethodError in ItemsController#import
undefined method `each' for nil:NilClass
Extracted source (around line #27):
25
26
27
28
29
30
@tubbo
tubbo / gist:6717783
Last active December 24, 2015 00:39
#the user model contains this association:
has_one :employee, autosave: true
# The auth hash contains all necessary data
def self.from_omniauth(auth)
where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
user = User.create \
provider: auth.provider
uid: auth.uid
name: auth.info.name
@tubbo
tubbo / data.rb
Last active December 24, 2015 00:49 — forked from chewmanfoo/data.rb
# WAT
var Script = require('deployd/lib/script');
var _run = Script.prototype.run;
Script.prototype.run = function(ctx, domain, fn) {
if (typeof domain === 'object') {
domain.require = function(module) {
return require(module);
};
domain.context = function() { // access Context via context()
return ctx;
@tubbo
tubbo / transaction.rb
Last active December 24, 2015 10:09 — forked from gerep/transaction.rb
def self.total_volume(transactions)
return transactions.amount unless transactions.is_a? Array
transactions.reduce(0) do |total, transaction|
total += transaction.amount
end
end