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 FetchEvent | |
extend ActiveSupport::Concern | |
def fetch_additional_photo | |
@offset, limit, fixed = 50, 50, 50 | |
excluding_pid_lists = [].join(',') | |
0.upto(@offset) do |i| | |
increment = (fixed*i) | |
@offset+=increment |
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
##Candidate: | |
validates :user_id, presence: { error_code: 9001, | |
developer_message: I18n.t('validations.developer_message.required'), | |
more_info: I18n.t('name.required.more_info') } | |
validates :user_id, uniqueness: true, presence: { error_code: 9001, | |
developer_message: I18n.t('validations.developer_message.required'), | |
more_info: I18n.t('name.required.more_info') } |
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 Company < ActiveRecord::Base | |
validates :name ,presence: {error_code: 9001, | |
developer_message: I18n.t('validations.developer_message.required'), | |
more_info: I18n.t('name.required.more_info') | |
} | |
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 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] |
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
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
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
# 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
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
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 |