Editing:
- Copy:
Command + C
- Cut:
Command + X
- Paste:
Command + V
- Cursor to end of line:
Command + Right Arrow
- Cursor to beginning of line:
Command + Left Arrow
Command + C
Command + X
Command + Tab
Command + Tab (Release tab and continue holding command. Select an app with left / right arrow)
Command + ~
Command + Space
class NestedAttributesUniquenessValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, items) | |
items = items.reject(&:_destroy) # let's ignore the items to be destroyed here | |
unless items.map(&options[:field]).to_a.uniq.size == items.size | |
record.errors[attribute] << "must be unique" | |
field = options[:field] | |
values = items.map {|item| item.send(field) } | |
duplicates = items.find_all {|item| values.count(item.send(field)) > 1 && item.id.nil? } | |
duplicates.each { |obj| obj.errors[field] << "has already been taken" } | |
end |
def self.percent(*keys)
keys.each do |key|
define_method(key) do
h.number_with_precision(object.send(key) * 100.0, precision: 1)
end
define_method("display_#{key}") do
h.number_to_percentage(object.send(column_name) * 100.0, precision: 1)
end
class CompanyDecorator < BaseDecorator
delegate_all
currency :budget, :actual
end
class BaseDecorator < Draper::Decorator
delegate_all
def self.currency(*keys)
keys.each do |key|
define_method(key) do
h.number_with_precision(object.send(key), precision: 2)
end
class BaseDecorator < Draper::Decorator
delegate_all
def self.currency(*keys)
keys.each do |key|
define_method(key) do
end
define_method("display_#{key}") do
class BaseDecorator < Draper::Decorator
delegate_all
def self.currency(*keys)
end
end
class CompanyDecorator < BaseDecorator
delegate_all
def budget
h.number_with_precision(object.budget, precision: 2)
end
def display_budget
h.number_to_currency(object.budget, precision: 0)
class CompanyDecorator < BaseDecorator
delegate_all
currency :budget
end