province_id = Province.find_by_name(prov).try(:id)
mobile_info = MobileInfo.find(:first, :conditions => ["mobile_num = ? ", mobile_num.to_i])
support_amount_a = ProvinceMerchantChangeValue.find(:all, :select => "DISTINCT change_value_id", :conditions => ["status = 1 and merchant_id = ? and province_id =? and channel_id in (select id from channels where status = 1)", merchant_id, province_id]).map { |cv| cv.change_value_id }.compact support_amount_s = ChangeValue.find(:all,:select => "price" ,:conditions => ["id in (?)", support_amount_a]) \ .map { |cv| cv.try(:price).to_i }.compact
curl -d "channel=中信异度支付&action_type=娱人节-手机充值&user_indicate=13911731997&original_amount=10000"http://10.150.150.151:3000/search.json |
Mime::Type.register "application/json", :ejson config/initializers/mime_types.rb
ActiveSupport::CoreExtensions::Hash::Conversions::XML_PARSING.delete('symbol') ActiveSupport::CoreExtensions::Hash::Conversions::XML_PARSING.delete('yaml')
if defined?(ActiveRecord) # Include Active Record class name as root for JSON serialized output. ActiveRecord::Base.include_root_in_json = true # Store the full class name (including module namespace) in STI type column. ActiveRecord::Base.store_full_sti_class = true end ActionController::Routing.generate_best_match = false # Use ISO 8601 format for JSON serialized times and dates. ActiveSupport.use_standard_json_time_format = true # Don't escape HTML entities in JSON, leave that for the #json_escape helper. # if you're including raw json in an HTML page. ActiveSupport.escape_html_entities_in_json = false
@_cache = ActiveSupport::Cache::MemCacheStore.new( CONFIG['host'], { :namespace => "#{CONFIG['namespace']}::#{@name}" } ) localhost::callback_lock @_cache.write(pay_channel.channel_id,'true’) v = @_cache.read(pay_channel.channel_id) if v.nil? || v != 'true' return false else return true end end
gem 'composite_primary_keys', '6.0.1'
start_time = start_time.to_s.to_datetime.at_beginning_of_day end_time = end_time.to_s.to_datetime.end_of_day
m_order[:merchant_id] = (merchant.instance_of? MplusMerchant) ?merchant.id : merchant
require 'will_paginate' 修改controller文件中的index方法: # @products = Product.find(:all) @products = Product.paginate :page => params[:page], :per_page => 2 .pagination = will_paginate @mplus_orders, :class => 'digg_pagination'
gem 'spreadsheet', '~> 0.7.3' PROVINCE = %w{ 安徽 北京 福建 甘肃 广东 广西 贵州 海南 河北 河南 黑龙江 湖北 湖南 吉林 江苏 江西 辽宁 内蒙古 宁夏 青海 山东 山西 陕西 上海 四川 天津 西藏 新疆 云南 浙江 重庆 } MONTH = 1.upto(12).to_a def self.total_to_xls(year = '2012', opts = {}) book = Spreadsheet::Workbook.new sheet1 = book.create_worksheet months = MONTH months = opts[:month].to_s.split(/,/) if opts[:month] fixed_row = months.collect{ |m| m.to_s + '月' }.insert(0, '') sheet1.row(0).concat(fixed_row) row1 = [''] (months.size - 1).times { row1 << ['用户数', '金额', '订单数'] } sheet1.row(1).concat(row1.flatten!) row = 2 sheet1.row(row).insert(0, '全国') months.each_with_index do |m, i| sheet1.row(row).insert(i*3 + 1, self.monthly_users_count(m)) sheet1.row(row).insert(i*3 + 2, self.monthly_amount(m)) sheet1.row(row).insert(i*3 + 3, self.monthly_orders_count(m)) end PROVINCE.each do |province| row += 1 sheet1.row(row).insert(0, province) months.each_with_index do |m, i| sheet1.row(row).insert(i*3 + 1, self.monthly_users_count_by_province(m, province)) sheet1.row(row).insert(i*3 + 2, self.monthly_amount_by_province(m, province)) sheet1.row(row).insert(i*3 + 3, self.monthly_orders_count_by_province(m, province)) end end path = "tmp/phone_recharge.xls" book.write path path end
selected_conditions = base_conditions.inject({}) do |hash, data| hash[data.first] = data.last unless data.last.blank? hash end
return time_str if time_str.instance_of? Time return time_str if time_str.is_a? Time
Person.instance_eval do def species "Homo Sapien" end end
class Foo end metaclass = (class << Foo; self; end) metaclass.class_eval do def species "Homo Sapien" end end end
obj = Object.new if obj.respond_to?("talk") obj.talk else puts "Sorry, object can't talk!" end request = gets.chomp if book.respond_to?(request) puts book.send(request) else puts "Input error" end
def method_missing(method, *args) if method.to_s =~ /(.*)_with_cent$/ attr_name = $1 if self.respond_to?(attr_name) '%.2f' % (self.send(attr_name).to_f / 100.00) else super end end end
def self.method_missing(method_sym, *arguments, &block) if method_sym.to_s =~ /^n_(.*)$/ # 可以用Channel.n_JunBao来取得君宝的渠道 # Bug fix: 纠正高阳的channel_name = 19Pay而不是Yj19Pay的问题 # 即添加Channel.n_19Pay,可以在对Configs::Yj19PayChannel评估修改ChannelName的风险后删除 process_class_name = ($1 == '19Pay' ? "Yj19Pay" : $1) find_by_process_class(process_class_name) else super end end
def method_missing(meth, *args, &blk) # 支持 suspending? ending? init? force? if meth.to_s =~ /(.*)\?$/ return is_status?($1) end # 支持 stat_to_init stat_to_suspending stat_to_ending stat_to_force if meth.to_s =~ /^stat_to_(.*)$/ return trans_stat_to($1) end # 不要丢了super super end
if bank_order.present? data_hash.each_pair { |k, v| bank_order.send("#{k}=", v) } else bank_order = BankOrder.new data_hash end
在Rails 3之前的版本,你必須使用<%=hevent.name %>如此HTML才會被逸出防止XSS網路攻擊。在Rails 3之後預設就會逸出。如果不要逸出,請使用<%= rawevent.name %>或<%= event.name.html_safe! %>。網路安全一章有針對XSS進一步的說明。
def f1 yield if block_given? end def f2(&p) p.call if block_given? end
http://noops.me/?p=133
http://robbin.iteye.com/blog/307271
https://ruby-china.org/topics/15853
http://blog.linjunhalida.com/blog/ruby-memory-leak-debug/
http://blog.linjunhalida.com/blog/librr-debug-cpu-usage-high/
gem
https://github.com/binarylogic/memorylogic
https://github.com/noahd1/oink
31. nginx 配置说明
https://github.com/biti/passenger-doc-zh/wiki/Passenger%E7%94%A8%E6%88%B7%E6%89%8B%E5%86%8Cnginx%E7%89%88
32. 查看passenger使用情况
rvmsudo passenger-memory-stats
33. Resque 和 Sidekiq 的区别
http://grantcss.com/blog/2015/01/21/difference-between-resque-and-sidekiq/
34. secret_token
A secret is required to generate an integrity hash for cookie session data. Use config.secret_token = "some secret phrase of at least 30 characters"in config/initializers/secret_token.rb
OK
rake secret