Whatever
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Message < Base | |
belongs_to :attachable, polymorphic: true, foreign_type: :attachable_class | |
end | |
class Photo < Base | |
has_many :messages, as: :attachable, foreign_type: :attachable_class | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scope :either, ->(a, b){where(where(profile: a, block: b).where(profile: b, block: a).where_values.instance_exec { self[0].and(self[1]).or(self[2].and(self[3]))})} | |
# or | |
def self.either(a,b) | |
pb = Arel::Table.new(:profile_blocks) | |
pb[:profile_id].eq(a).and(pb[:block_id].eq(b)).or(pb[:profile_id].eq(b).and(pb[:block_id].eq(a))) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PhotosController < ApplicationController | |
respond_to :json | |
def index | |
respond_with load_photos | |
end | |
def show | |
respond_with load_photo | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Gear | |
attr_reader :chainring, :cog, :wheel | |
def initialize(chainring, cog, rim, tire) | |
@chainring = chainring | |
@cog = cog | |
@wheel = Wheel.new(rim, tire) | |
end | |
def ratio | |
chainring / cog.to_f | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- days = 0..7 | |
- hours = 8..18 | |
%table | |
- days.each do |d| | |
%th= (Time.now + d.day).strftime("%A") | |
- hours.each do |h| | |
%tr | |
- days.each do |d| | |
%td= Time.parse("0001-01-01 #{h}:00:00 UTC").strftime '%l %p' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserSerializer < ActiveModel::Serializer | |
attributes :id, :name, :phone, :email, :balance, :children, :balance | |
def attributes | |
data = super | |
data[:children] = User.find(data[:id]).subordinates.any? | |
data | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready -> | |
$(".simple_form").on("ajax:success", (e, data, status, xhr) -> | |
$(".list").append xhr.responseText | |
).bind "ajax:error", (e, xhr, status, error) -> | |
$(".list").prepend xhr.responseText |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Regular Expression for URL validation | |
# | |
# Converted Diego Perini's regexp to ruby | |
# | |
# Author: James Robey | |
# Updated: 2013/02/07 | |
# | |
# Credits to Matt (mparodi) | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def method(grid,root,rev = false) | |
grid.send(rev ? :reverse_each : :each) do |row| | |
row.send(rev ? :<< : :unshift, @num) | |
@num += 1 | |
end | |
new_row = [] | |
root.times do | |
new_row.send(rev ? :unshift : :<<, @num) | |
@num += 1 |