Skip to content

Instantly share code, notes, and snippets.

def create_location_with_random_trait(options = {})
# there might be a way to retrieve this from the factory girl object directly to avoid duplicat
trait = [:trait1, :trait2, :trait3].sample
FactoryGirl.create(:location, trait, options)
end
# OR
module FactoryGirl
ActiveAdmin.register OleCore::Subscription, as: "Subscriptions" do
controller do
def scoped_collection
resource_class.includes(:account)
end
end
filter :id
index do
ActiveAdmin.register OleCore::Subscription, as: "Subscriptions" do
controller do
def scoped_collection
resource_class.includes(:account)
end
end
filter :id
filter :account_name, as: :string
filter :trial_expiry_at
class User
attr_accessible :full_name
belongs_to :company
end
class Company
attr_accessible :name
has_many :users
has_one :primary_admin, class_name: 'User', conditions: ['users.primary_admin = true']
@laspluviosillas
laspluviosillas / example.rb
Created November 6, 2013 20:04
Example subscription decorator structure.
class ChargifySubscription < SimpleDelegator
def addons_count
# Implementacion aqui
end
def price
# Implementacion aqui
end
end
@laspluviosillas
laspluviosillas / question1.rb
Last active October 18, 2017 16:20
Interview Question #1
class Husband < ActiveRecord::Base
attr_accessible :full_name
has_one :wife
end
class Wife < ActiveRecord::Base
attr_accessible :full_name
belongs_to :husband
end
@laspluviosillas
laspluviosillas / question2.rb
Last active December 27, 2015 17:18
Interview Question #2
# (Rails 3.2)
# Number of Units in the system: 30,000
# Number of Courses in the system: 50.
# Unit:
# Properties
# -- active: boolean
# -- course_id: int
@laspluviosillas
laspluviosillas / question3.rb
Last active December 27, 2015 17:18
Interview Question #3
class Author < ActiveRecord::Base
attr_accessible :name, :admin # :name => string, :admin => boolean
has_many :posts
end
class Post < ActiveRecord::Base
attr_accessible :name, :description # :author_id => int, :name => string, :description => string
belongs_to :author
has_many :comments
end
@laspluviosillas
laspluviosillas / application_helper.rb
Last active December 27, 2015 17:18
Interview Question #4
module ApplicationHelper
def pretty_user_name
"<span class='pretty'>" + @user.first_name + " " + @user.last_name + "</span>"
end
end