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 self.convert_key_to_human_readable_name(obj, options) | |
messages = [] | |
class_name = obj.class.name.underscore | |
errors = obj.errors.messages | |
separator = options[:separator].present? ? options[:separator] : ',' | |
errors.each do |key, value| | |
base_key = (options[key].present? && options.keys.include?(key)) ? options[key].to_s : key.to_s | |
values = value.each { |val| val.downcase } | |
values.flatten.join(" #{separator}") unless values.empty? | |
if key == :base |
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
#For executing corn Jobs in server. | |
#set :whenever_command, "bundle exec whenever" | |
#require "whenever/capistrano" | |
require "delayed/recipes" | |
default_run_options[:pty] = true | |
set :ssh_options, {:forward_agent => true} | |
set :rails_env, "production" |
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
# the day_statistics | |
include Mongoid::Document | |
field :date, type: Date | |
field :entity_id, type: Integer | |
field :todays_statistics, type: Hash | |
field :hotel_inventory, type: Hash |
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 OrderService | |
class << self | |
def find_or_create_purchase_for_order(order, credit_card_id, shipping_fee = 0.0) | |
buyer, seller, purchase, s_state = order.buyer, order.seller, Purchase.find_by_user_id_and_order_id(user.id, order.id), order.cart.shipping_address.state.upcase | |
sale_tax = SalesTax.find_by_user_id(vendor.id).send(s_state) rescue 0.0 | |
total_chargeable_amount = calculate_total order.price, sale_tax, vendor.reppio_cut | |
create_purchase order, credit_card_id, shipping_fee, total_chargeable_amount, sales_tax # updated here |
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 AlterUser < ActiveRecord::Migration | |
def up | |
rename_table :users, :customers | |
add_column :customers, :username, :string, limit: 25 | |
change_column :customers, :email, :string, limit: 100 | |
rename_column :customers, :password, :hashed_password | |
add_column :customers, :salt, :string, limit: 40 | |
add_index :customers, :username | |
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
# in migration | |
class AddPermalinkToPost < ActiveRecord::Migration | |
def change | |
add_column :posts, :permalink, :string | |
end | |
Post.find_each(&:save) | |
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
def number_with_check_digits(number) | |
digits = number.to_s.reverse.scan(/\d/).map { |x| x.to_i } | |
digits = digits.each_with_index.map { |d, i| | |
d *= 2 if i.even? | |
d > 9 ? d - 9 : d | |
} | |
sum = digits.inject(0) { |m, x| m + x } | |
mod = 10 - sum % 10 | |
mod==10 ? 0 : mod | |
digits = number.to_s.reverse.scan(/\d/).map { |x| x.to_i } |
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
Payment.transaction(isolation: :serializable) do # a postgresql feature for uniq transaction available on rails4 now | |
Payment.with(:line_item_id => line_item_id, :service_id => service_id) do |payment| | |
payment.process # | |
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
# Expected | |
# "error": { | |
# "status": 422, | |
# "code": "some_object/validation", | |
# "message": "Cannot create the {some_object} because provided data is not valid", | |
# "details": "More thorough description of a problem and probably even solution for curious users", | |
# "href": "http://some.url/to-describe/the-problem/in-even-more-details/optional", | |
# "errors": { | |
# "name": { | |
# "code": "validation/missing_required", |
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 ActiveModel | |
class Errors | |
attr_accessor :error_code, :developer_message, :more_info | |
def add(attribute, message = :invalid, options = {}) | |
options.each { |k,v| instance_variable_set("@#{k}", v) } | |
message = normalize_message(attribute, message, options) | |
if exception = options[:strict] |
OlderNewer