Skip to content

Instantly share code, notes, and snippets.

View tubbo's full-sized avatar
😎
losing my sight, losing my mind, go to the general to save some time

Tom Scott tubbo

😎
losing my sight, losing my mind, go to the general to save some time
View GitHub Profile
@tubbo
tubbo / polymorphic.rb
Last active April 13, 2017 20:22 — forked from laspluviosillas/polymorphic.rb
Issue with polymorphic associations
class Task < ActiveRecord::Base
has_one :notification_preference, as: :notifee
accepts_nested_attributes_for :notification_preference
end
class NotificationPreference < ActiveRecord::Base
belongs_to :notifee, polymorphic: true
end
@tubbo
tubbo / Terminal
Last active January 26, 2017 16:42 — forked from kitsuneyo/Terminal
Game::Note.new
(irb):3: warning: toplevel constant Note referenced by Game::Note
=> #<Note id: nil, article_id: nil, type: nil, category: nil, body: nil, cite_url: nil, cite_title: nil, cite_website: nil, created_by_id: nil, created_at: nil, updated_at: nil>
# ^^ This is a new Note class object, not a Game::Note class object
@tubbo
tubbo / models.rb
Last active March 21, 2021 21:32 — forked from mfifth/models.rb
class User < ActiveRecord::Base
has_many :memberships
has_many :groups, through: :memberships
end
class Group < ActiveRecord::Base
has_many :memberships
has_many :members, class_name: 'User', through: :memberships
end
@tubbo
tubbo / order.rb
Last active January 4, 2017 21:25
class Order < ApplicationRecord
has_many :order_items, dependent: :destroy
def amount
order_items.sum :total_price
end
end
@tubbo
tubbo / activeadmin.rb
Last active December 13, 2016 20:09 — forked from bennyzr/gist:0bd5d7c59c69010dec73fa4576a5a04d
Insert tag into Active Admin body tag to disable turbolinks
ActiveAdmin::Views::Pages::Base.class_eval do
def build(*args)
super
add_classes_to_body
add_attributes_to_body
build_active_admin_head
build_page
end
def add_attributes_to_body
<div class='main-content'>
<h2 class='greeting'>Free hi-res stock images for both personal & commercial use.</h2>
<ul class='optionsnavi'>
<li class='dropdown'>
<button class='dropbtn'>
Sort By <i class="fa fa-sort-desc" aria-hidden="true"></i>
</button>
<div id='myDropdown' class='dropdown-content'>
<%= link_to "Latest", :sort => "created_at asc" %>
@tubbo
tubbo / model.rb
Last active October 5, 2016 14:54 — forked from wolfravenous/model.rb
Need to move Logic From the View into The Model, Rails v. 4.2, The current entry in the model for setting the gender in comments, works correctly because comment is an attribute of report. Would like to move the logic currently in the view to the model, however I am unsure of how to because content is an attribute of intro, which is a nested res…
def genderized_comment
comment.gsub(/HESHE/, gender_pronoun.capitalize)
end
def gender_pronoun
gender == 'female' ? 'she' : 'he'
end
@tubbo
tubbo / test.rb
Last active August 5, 2016 17:32
params = {}
room = { wall:"red", size:4 }
params[:house] = room
puts params[:house][:wall] # => 'red'
@tubbo
tubbo / model.rb
Created June 28, 2016 19:21
Rails model query
Content::LibraryPage.each { |c| puts c.live.title if c.live.title.in?(months) }
# The error message
undefined method `comments_path' for #<#<Class:0x007f01f0513be8>:0x00000003b43928>
Did you mean? font_path
Extracted source (around line #1):
1
2
3
4