This file contains 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
StandardNewsletter.daily.publish |
This file contains 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
$ rails generate newsletter standard daily weekly | |
create app/newsletters/standard_newsletter.rb | |
create app/views/standard_newsletter/daily.html.emv | |
create app/views/standard_newsletter/daily.text.emv | |
create app/views/standard_newsletter/weekly.html.emv | |
create app/views/standard_newsletter/weekly.text.emv |
This file contains 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
# Render a partial in a different format | |
# | |
# Parameter : String or Array | |
# Usage : | |
# <% with_format('html') do %> | |
# <%= render(partial: 'partial') %> | |
# <% end %> | |
def with_format(formats) | |
original_formats = self.formats | |
self.formats = formats.kind_of?(Array) ? formats : [formats] |
This file contains 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
// Reload images on failure every x seconds | |
$("img").error(function() { | |
var path = $(this).data('src'); | |
var img = $(this); | |
// Put back mock image | |
$(img).attr('src', 'http://placehold.it/56x56'); | |
// Increment loading counter | |
var attempt = ($(img).data('attempt') || 0); |
This file contains 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
package ch.hegarc.ig.clientscomptes.configuration; | |
import java.io.File; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import java.util.Properties; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
import org.apache.commons.lang3.StringUtils; |
This file contains 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
# has_attached_file :image, configuration | |
# background_upload_for :image | |
module PaperclipBackgroundUpload | |
extend ActiveSupport::Concern | |
included do | |
def background | |
@background || false | |
end |
This file contains 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
# This core extension aims to manage Deadlocks | |
# with a proper ActiveRecord exception. | |
# | |
# It only works for mysql2 | |
# | |
# Example: | |
# | |
# MyModel.transaction do | |
# begin | |
# record1 = MyModel.find(:id, lock: true) |
This file contains 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
# = AggregateField | |
# | |
# This module allows to create a virtual field from multiple fields | |
# | |
# Example: | |
# | |
# class DummyClass | |
# include AggregateField | |
# | |
# attr_accessor :first_name, :last_name |
This file contains 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
module SoftDeletable | |
extend ActiveSupport::Concern | |
def soft_delete! | |
find_each do |record| | |
record.soft_delete! | |
end | |
end | |
included do |
This file contains 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 UberRelation | |
include Enumerable | |
def initialize(scopes) | |
scopes.kind_of?(Array) or raise ArgumentError.new("Argument scopes is not an array!") | |
@scopes = scopes | |
end | |
def each(&block) | |
block_given? ? load.each{|scope| block.call(scope)} : load |