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
# Based on | |
# https://github.com/ng/paperclip-watermarking-app/blob/master/lib/paperclip_processors/watermark.rb | |
# Modified by Laurynas Butkus | |
module Paperclip | |
class Watermark < Processor | |
# Handles watermarking of images that are uploaded. | |
attr_accessor :format, :whiny, :watermark_path, :position | |
def initialize file, options = {}, attachment = nil |
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
# Add option to deliver all mails to one address. Useful in staging environment. | |
# config.action_mailer.delivery_method = :catchall | |
module ActionMailer | |
class Base | |
def perform_delivery_catchall(mail) | |
original_to = mail.to | |
mail.to = "youremail@yourdomain" | |
mail.cc = "" |
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 Item < ActiveRecord::Base | |
named_scope :ascend_by_optional_category_title, | |
:joins => "LEFT JOIN categories AS optional_categories ON optional_categories.id=items.category_id", | |
:order => "optional_categories.title" | |
named_scope :descend_by_optional_category_title, | |
:joins => "LEFT JOIN categories AS optional_categories ON optional_categories.id=items.category_id", | |
:order => "optional_categories.title DESC" |
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 Globalize | |
module ActiveRecord | |
class Adapter | |
def write_with_hash(locale, name, value) | |
if value.is_a?(Hash) | |
value.each do |locale, value| | |
self.write_without_hash(locale, name, value) | |
end | |
else |
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
# Close unclosed tags | |
def fix_invalid_html(html) | |
Nokogiri::HTML::DocumentFragment.parse(html).to_html | |
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
class WillPaginateJqueryMobileRenderer < WillPaginate::ViewHelpers::LinkRenderer | |
def container_attributes | |
super.merge({ | |
:'data-role' => 'navbar' | |
}) | |
end | |
def pagination | |
@options[:page_links] ? windowed_page_numbers : [] |
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
# Initializer: | |
# require 'mail_delivery_catchall.rb' if Rails.env.staging? | |
# Rails 3 | |
module ActionMailer | |
class Base | |
class << self | |
def deliver_mail_with_catchall(mail, &block) |
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
# depends on i18n_multi_locales_form plugin | |
# rails plugin install https://github.com/ZenCocoon/i18n_multi_locales_form.git | |
module MultiLocaleFieldBuilder | |
def multi_locale_field(method, opts = {}) | |
opts = { | |
:type => :text_field | |
}.merge(opts) | |
type = opts.delete(:type) |
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 RenderRemoteHelper | |
# Generate javascript for rendering remote resource | |
# * +url+ - resource url | |
# * +view+ - element id to update | |
def render_remote(url, view = 'remote', options = {}) | |
options[:update] = view | |
options[:url] = url | |
options[:method] = :get | |
render :inline => %{<span id="#{view}"><p>Loading...</p><script |
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
# Convert vodafone360 contacts html to VCF | |
require 'rubygems' | |
gem 'nokogiri' | |
gem 'vpim' | |
require 'nokogiri' | |
require 'vpim/vcard' | |
Dir.glob("html/*.html").each do |file| | |
doc = Nokogiri.parse(File.read(file)) |