Skip to content

Instantly share code, notes, and snippets.

View slbug's full-sized avatar

Alexander Grebennik slbug

  • Poland
  • 07:16 (UTC +02:00)
View GitHub Profile
Using the default profile...
Feature: Mount an Uploader on ActiveRecord class
In order to easily attach files to a form
As a web developer using CarrierWave
I want to mount an uploader on an ActiveRecord class
Background:
Given an uploader class that uses the 'file' storage
And an activerecord class that uses the 'users' table
And the uploader class is mounted on the 'avatar' column
require 'date'
require 'time'
require 'active_support/all'
p_inf = 1.0 / 0.0
n_inf = -1.0 / 0.0
module InfiniteComparable
extend ActiveSupport::Concern
require 'date'
require 'time'
require 'active_support/all'
p_inf = 1.0 / 0.0
n_inf = -1.0 / 0.0
class Date
def <=> (other)
conversion = :"to_#{self.class.name.downcase}"
# Code before:
resources :messages do
resources :comments
end
resources :posts do
resources :comments
resources :images, only: :index
end
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'rack', github: 'rack/rack'
gem 'pg'
GEMFILE
system 'bundle'
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'rack', github: 'rack/rack'
gem 'i18n', github: 'svenfuchs/i18n'
gem 'public_activity', github: 'pokonski/public_activity'
gem 'sqlite3'
GEMFILE
[{"id":100,"type":"hotel","title":"Hotel in London","start":"2014-10-02","end":"2014-10-05","url":"/en/trips/9/hotels/100/edit","editable":false,"backgroundColor":"#e4d3eb","borderColor":"#e4d3eb","textColor":"#000","className":"trip-hotel trip-item-100"}]
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails'
gem 'arel'
gem 'rack'
gem 'i18n'
gem 'sqlite3'
gem 'destroyed_at'
GEMFILE
/* ### Transitions between Sections ##################################################################### */
(function() {
// detect if IE : from http://stackoverflow.com/a/16657946
var ie = (function(){
var undef,rv = -1; // Return value assumes failure.
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
var trident = ua.indexOf('Trident/');
if (msie > 0) {
@slbug
slbug / Gemfile
Created February 25, 2016 14:50
Deadlock using sidekiq & fog
ruby '2.3.0'
source 'http://rubygems.org'
gem 'sidekiq'
gem 'fog'
gem 'mime-types'