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 Mechanize | |
alias_method :original_get, :get | |
def get *args | |
doc = original_get *args | |
encoding = doc.encodings.last | |
doc.content.encode!('UTF-8', encoding) | |
doc | |
end | |
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
module AutosaveNestedErrors | |
extend ActiveSupport::Concern | |
included do | |
def autosave_nested_errors | |
valid? # can invoke errors second time | |
errors = self.errors.to_hash | |
reflections.each do |name, association| | |
if association.options[:autosave] |
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
# container - may be null or may be jquery tag | |
# widget - widget object | |
# func - can be string (append, prepend, after, before) or function with: container and content arguments | |
@Joosy.Modules.NewWidgetsManager = | |
addWidget: (container, widget, func) -> | |
uuid = container?.attr('id') || Joosy.uuid() | |
container?.attr('id', uuid) | |
render = -> |
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
def autosave_errors(params) | |
#valid? | |
errors = {} | |
params.each do |key, nested_params| | |
_, association_name = key.to_s.match(/\A(.+)_attributes\Z/).to_a | |
if association_name | |
association = association(association_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 Handlers | |
class Rb | |
def self.call(template) | |
if template.virtual_path.split('/').last =~ /^_/ | |
"instance_eval { #{template.source} }" | |
else | |
"instance_eval { #{template.source} }.to_json" | |
end | |
end | |
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
$.fn.sticky = function (obj, options) { | |
var $w = $(window); | |
return this.each(function () { | |
var o = $(this); | |
var height = o.outerHeight(); | |
var placeholderObj = $("<div/>").css({ | |
height: height + "px", | |
width: o.outerWidth() + "px", | |
top: o.css('top'), |
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
= form_for @search, url: collection_path, | |
as: :q, | |
builder: ActiveAdmin::Filters::CustomFormBuilder, | |
html: {method: :get, class: :filter_form} do |f| | |
= f.input :code_contains, as: :string | |
= f.input :code_contains, as: :filter_string | |
= f.form_buffers.last |
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
# TODO can be optimized to use custom class and `model_ids` method | |
module SortPhotos | |
def sort_photos!(ids) | |
raise ArgumentError, "ids isn't an array" if !ids.is_a?(Array) | |
ids.map!(&:to_i) | |
old_ids = self.photo_ids | |
ids = ids - (ids - old_ids) | |
raise ArgumentError, "Not all the ids were passed to sort! method" if old_ids.size != ids.size | |
reflections[:photos].klass.update_all(['position = FIND_IN_SET(id, ?)', ids.join(',')], {:id => ids}) |
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
rewrite ^/sitemap1.xml.gz /sitemaps/$host/sitemap1.xml.gz last; | |
rewrite ^/sitemap_index.xml.gz /sitemaps/$host/sitemap_index.xml.gz last; | |
# or | |
location /sitemap { | |
# it can be already switched on for globally | |
# gzip_static on; | |
rewrite ^/sitemap.xml /sitemaps/$host/sitemap.xml last; # that's will catch .gz files and served as normal static file, but with gzip header |
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
namespace :routes do | |
desc "Writes doc/routes.html. Requires Graphviz (dot)" | |
task :visualizer => :environment do | |
File.open(Rails.root.join('doc', 'routes.html'), 'wb') do |f| | |
f.write Rails.application.routes.router.visualizer | |
end | |
end | |
end |