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
#test/test_helper.rb | |
# | |
# Looks up the error message for the given error in the locales | |
# | |
def localized_validation_error_message(record, attribute, error_name) | |
I18n.t("activerecord.errors.models.#{record.class.name.underscore}.attributes.#{attribute}.#{error_name}") | |
end | |
# | |
# @return [Boolean] +true+ if the given error was actually included in the validation errors |
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
# Don't forget to turn auto-loading all helpers off: | |
# config.action_controller.include_all_helpers = false | |
class ActionController::Base | |
class << self | |
def all_helpers(options = {}) | |
all_helpers_from_path(helpers_path) - Array(options[:except]) | |
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
module Lockable | |
def self.included(base) | |
base.class_eval do | |
named_scope :not_locked, :conditions => {:deleted_at => nil} | |
named_scope :locked, :conditions => "#{table_name}.deleted_at IS NOT NULL" | |
end | |
end | |
# Locks the record by setting the deleted_at attribute | |
# to the current time. |
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 module contains all necessary methods to render liquid templates | |
#in a controller. | |
module LiquidHelpers | |
module Rendering | |
def self.included(base) | |
base.class_eval do | |
helper_method :render_liquid if respond_to?(:helper_method) | |
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
before_validation :ensure_default_date_format | |
# Parses dates in european date formats before saving a record | |
# Accepts dates in the format "dd.mm.yyyy" and "yyyy-mm-dd" | |
#-------------------------------------------------------------- | |
def ensure_default_date_format | |
self.class.columns.select {|c| c.type == :date}.each do |c| | |
value_before_type_cast = send("#{c.name}_before_type_cast") | |
date = Date.try(:parse, value_before_type_cast, :eu) || Date.parse(value_before_type_cast) | |
write_attribute(c.name, date) |
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
# Example: Weekday Selection | |
# #weekdays{:data => {:toggle => :checkboxes}} | |
# %label Weekdays | |
# - [:mon, :tue, :wed, :thu, :fri, :sat, :sun].each do |wday| | |
# = f.label wday | |
# = f.check_box wday | |
# Creates a bootstrap buttonset and hides the original checkboxes | |
#-------------------------------------------------------------- | |
initializeCheckboxButtonsets: () -> |
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
#Overrides the default way how rails marks form fields with errors. | |
#In this version, it only adds the class 'error' to label and element | |
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| | |
if html_tag =~ /<(input|label|textarea|select)/ | |
html_field = Nokogiri::HTML::DocumentFragment.parse(html_tag) | |
html_field.children.add_class 'error' | |
html_field.to_s | |
else | |
html_tag |
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
%Creates an image displaying the compilation of a compiler and the result | |
\begin{picture}(300,75) | |
\put(0,25) {\tdiagram(from Q to M_2 in Q)} | |
\put(65,0) {\tdiagram(from Q to M_1 in M_1)} | |
\put(130,25) {\tdiagram(from Q to M_2 in M_1)} | |
\end{picture} | |
%Creates an image of a compiler chain | |
\begin{picture}(200,50) | |
\put(0,0) {\tdiagram(from Q to Z in Q)} |