
ruby on rails
文章平均质量分 92
Men-DD
这个作者很懒,什么都没留下…
展开
-
生成二维码PDF合并PDF压缩
modelclass Model def created_pdf tmp_dir = 'tmp_file/'+Time.now.strftime('%Y%m%d') file_dir = Rails.root.join('public', tmp_dir) FileUtils.mkdir_p file_dir file_name = Time.now....原创 2019-03-08 16:55:20 · 313 阅读 · 0 评论 -
Ruby On Rails 之 ElasticSearch
ElasticSearch中内置了许多分词器, standard, english, chinese等, 中文分词效果不佳, 所以使用ik, 以及pinyinelasticsearch gemgem 'elasticsearch-model', '~> 5.0', '>= 5.0.1'gem 'elasticsearch-rails', '~> 5.0', '&am原创 2018-11-20 17:01:54 · 667 阅读 · 0 评论 -
Rails打造微服务之RabbitMQ
MQ 全称为 Message Queue, 消息队列(MQ)是一种应用程序对应用程序的通信方法。应用程序通过读写出入队列的消息(针对应用程序的数据)来通信,而无需专用连接来链接它们。RabbitMQ 是一个在 AMQP 基础上完整的,可复用的企业消息系统。他遵循 Mozilla Public License 开源协议。RabbitMQ WIKI:https://zh.wikipedia.org...原创 2018-11-15 09:29:22 · 578 阅读 · 0 评论 -
capistrano + rails + rvm + bundler + puma 快速部署Rails
Gemfilegem 'capistrano', '~> 3.6'gem 'capistrano-rails', '~> 1.2'gem 'capistrano-rvm'gem 'capistrano-bundler'gem 'capistrano3-puma', require: falsedeploy.rb# config valid only for curren...原创 2018-11-14 11:41:54 · 498 阅读 · 0 评论 -
Ruby-ActiveRecord(pluck,find_each,transactive,after_commit,touch,changes,connection_pool,arel_table)
推荐使用: Ruby-ActiveRecord pluck,find_each,transactive,after_commit,touch,changes,connection_pool,arel_table翻译 2016-04-11 10:10:20 · 1013 阅读 · 0 评论 -
resque VS sidekiq & AMQP - RabbitMQ 消息处理
resque & sidekiqresque 一个 worker 通过 fork 方式来产生多个 worker 处理多个任务fork 一个进程,操作系统会建立一个独立分开的地址空间,并且从父进程复制所有的内存片段到这个地址里面去。 这就意味着对于操作系统来说,对于 fork 的进程切换上下文,因为需要保存和加载所有数据,所以代价更大。 而且如果父进程死掉了,这些 fork 的子进程没有退出的话,将会原创 2016-01-18 11:37:31 · 1963 阅读 · 0 评论 -
ruby json(1.8.3) install error
ruby 2.2.2& 2.2.3 install json 1.8.3 errorGem::Ext::BuildError: ERROR: Failed to build gem native extension. /home/ubuntu/.rvm/rubies/ruby-2.2.2/bin/ruby -r ./site原创 2015-10-29 15:26:04 · 2666 阅读 · 0 评论 -
Rails 异常处理 && 性能
Rails 异常处理 的多种处理方法 1. routes match path via all to controlleraction2. applicationrb 的 exception_app3. exception_notification configenvironments 4. Slack exception_notification原创 2015-07-06 18:22:49 · 1787 阅读 · 0 评论 -
redis 的图标挺有意思的
redis 的使用1.安装redis官网的步骤安装redis (http://redis.io/download)$ wget http://download.redis.io/releases/redis-2.8.15.tar.gz$ tar xzf redis-2.8.15.tar.gz$ cd redis-2.8.15$ make...原创 2014-09-16 10:12:32 · 9807 阅读 · 0 评论 -
有趣的程序
1.to_procclass Array def to_proc proc { |receiver| receiver.send *self } endend[ 'Hello', 'Goodbye' ].map &[ :+, ' BeiJing!' ]#=> ["Hello BeiJing!", "Goodbye BeiJing!"]recei原创 2014-08-29 17:27:50 · 1366 阅读 · 0 评论 -
Ruby 零碎点
1. Ruby 中纯数据结构 ( Struct 与 OpenStruct )讲一下它俩之间的区别:Struct 需要开头明确声明字段; 而 OpenStruct 人如其名, 随时可以添加属性Struct 性能优秀; 而 OpenStruct 差点, 具体的性能差距可看这里:http://stackoverflow.com/questions/1177594/ruby-struct-vs-openstructStruct 是 Ruby 解释器内置, 用 C 实现; OpenStruct 是 Rub原创 2014-08-06 09:44:29 · 1202 阅读 · 0 评论 -
创建序列以及对应的视图
项目需要保证订单号的唯一在使用时间生成时发现在业务量比较大的情况下,还是会出现重复情况解决方案:创建一个序列表和视图 从视图中取CREATE SEQUENCE general_order_no_seq INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1;原创 2014-07-31 09:34:55 · 1556 阅读 · 0 评论 -
AWS SQS DOC AND RUBY DEMO
# Amazon SQS## Amazon Simple Queue Service (SQS) 是一个可伸缩且可靠的消息传递框架,可以使用它简便地创建、存储和获取文本消息。可以使用它构建基于 Amazon Web Services 的应用程序。使用 SQS 是构建松散耦合的 Web 应用程序的好方法。只需根据使用量为消息付费。整个队列框架在 Amazon 数据中心的安全环境中运行原创 2014-07-30 11:38:08 · 2497 阅读 · 0 评论 -
Rails 4.0.0 开发环境一切正常,到生成环境发现 无法找到 css 和 js
1.gemFile在rails 4 之后没有grop 了 要记得哦# group :assets dogem 'sass-rails', '~> 4.0.0'gem 'coffee-rails', '~> 4.0.0' gem 'uglifier', '>= 1.3.0'# end# 页面渲染gem 'jquery-rails' #这个gem 'exe原创 2014-05-23 15:06:57 · 3609 阅读 · 0 评论 -
txt 转为 csv 可以通用的 工具
Ruby Txt 转为 CSV 通用的工具require 'csv'namespace :sys_file_conver do desc "把txt数据导入到csv中" task :txt_to_csv => :environment do amount = 100 head_hash = { '对账文件名称' =>[12]原创 2014-05-08 14:02:55 · 6803 阅读 · 0 评论 -
Liunx Crontab 定时的逻辑
在做活动项目时需要对时间的限制 就写模仿 crontab 写了一个# utf-8# '* * * * *' -> 分 时 日 月 周# '* * * 1-3 *' -> 分 时 日 月 周# '* * * 1,2,3 *' -> 分 时 日 月 周# 01-59 01-23, 01-31, 01-12, 0-6# simple : CrontabUtil.原创 2014-04-29 09:38:51 · 1369 阅读 · 0 评论 -
puma 配置,启动脚本
配置: puma_server_conf.rb#!/usr/bin/env pumaapplication_path = '/srv/rorapps/discount_service'directory application_pathenvironment 'development'daemonize truepidfile "#{application_path}/tmp/pi原创 2014-04-26 18:14:14 · 4000 阅读 · 0 评论 -
Ruby 一些常用的细节
1.try 永远不会抛出异常 在 没有的时候 返回 nil province_id = Province.find_by_name(prov).try(:id)2.find(:first, :condotions) 方法 不言而与mobile_info = MobileInfo.find(:first, :conditions => ["mobile_num = ? ", mobi原创 2014-04-26 17:48:02 · 3186 阅读 · 0 评论 -
pow 的使用和常见问题
1.安装:$ curl get.pow.cx | shTo set up a Rack app, just symlink it into ~/.pow:$ cd ~/.pow$ ln -s /path/to/myapp2.ErrorError starting applicationYour原创 2014-04-26 16:31:15 · 2894 阅读 · 0 评论 -
关于ssl证书的格式转换以及各方式的使用 收集以及案例,工具soap-ui
关于ssl证书的格式转换以及各方式的使用 收集以及案例http://stackoverflow.com/questions/12162975/openssl-not-enough-dataopenssl x509 -inform der -in"c:\mydir\test.cer" -out"C:\mydir\certificate.pem"openssl pkcs12 -in"c:\mydir\test.pfx" -noce原创 2014-04-23 11:25:27 · 3312 阅读 · 0 评论 -
配置 Rails 应用程序
这个指南涵盖了 Rails 应用程序的配置和初始化设置.通过浏览这个指南,你将能:调整 Rails 应用程序的运作附加程序启动时运行的代码endprologue.初始化代码的位置Rails 提供四个标准的位置初始化代码config/application.rb运行环境相关的配置文件各初始化程序后初始化程序(初始化完成后运行的程序)先于Rails运行代转载 2014-04-16 18:45:44 · 4937 阅读 · 0 评论 -
修改rails项目的名字 需要修改哪些地方
如果需要修改rails项目的名字 大部分应该是修改了下面的这几个文件中的 App Name 就差不多了吧config.ruRakefileconfig/application.rbconfig/environment.rbconfig/environments/development.rbconfig/environments/test.rbconfig/routes.rbcon原创 2014-03-15 15:06:01 · 1676 阅读 · 0 评论 -
ActiveRecord 的查询按照某个虚拟字段排序
在Ruby-Chain上看到的一个关于 排序的讨论具体的业务场景是: 需要使用类似hacker news的投票算法进行排序。比如现在有个aticle模型,模型有个字段P 代表喜欢某篇文章的人数。T表示距离发帖已经过去的时间(单位为小时)地址:http://ruby-china.org/topics/17612http://blog.chh.tw/原创 2014-03-13 11:44:27 · 1758 阅读 · 0 评论 -
yaml to json 批量 以及 单个
YAML.load_file(path)[1].each_with_index {|hash, i| File.open("json/35#{num(i+1)}.json", "w") {|f| f << JSON.pretty_generate(hash) }}def num(i) return "0" + i.to_s if i.to_s.length < 2原创 2013-12-09 16:49:04 · 2708 阅读 · 0 评论 -
拼音字母搜索功能 之 gem
拼音字母搜索功能使用的gem: https://github.com/huacnlee/redis-search使用方法配置文件路径: config/initializers/redis_search.rb# -*- coding: utf-8 -*-require "redis"require "redis-namespace"require "原创 2013-12-04 11:25:55 · 2140 阅读 · 0 评论 -
Nginx + Unicorn 部署 Rails 完整配置
nginx+unicorn 完整配置,主要的是,nginx.conf 和 unicorn.rb 这两个配置文件1.配置nginx文件 sudo vim /opt/nginx/conf/nginx.conf#=== CPU ====user menxu menxu;worker_processes 2;worker_cpu_affinity 0000000原创 2013-12-02 18:09:10 · 8419 阅读 · 0 评论 -
MySQL 出现 Access denied for user 'root'@'localhost' (using password: YES) 错误
登录某台服务器的mysql时候总报错:mysql2/client.rb:58:in `connect': Access denied for user 'root'@'localhost' (using password: YES) (Mysql2::Error)原创 2013-11-28 15:29:39 · 5786 阅读 · 0 评论 -
ActiveSupport 工具函式庫
根据Ruby on Rails 實戰聖經的ActiveSupport 记录,感觉里面内容太多了,想把目录点概况的容易回忆一些Active Support 是 Rails 裡的工具函式庫,它也擴充了一些 Ruby 標準函式庫。除了被用在 Rails 核心程式中,你也可以在你的程式中使用。本章介紹其中的一小部分較為常用的功能。1. blank? 和 present?在翻译 2013-11-25 12:06:44 · 1457 阅读 · 0 评论 -
当Ruby的model名字出错时,在现实view时显示错误的提示
app/controllers/courses_controller.rb:1:in `'app/controllers/courses_controller.rb:1:in `'undefined method `key?' for nil:NilClass原创 2013-11-14 10:16:28 · 1200 阅读 · 0 评论 -
Ruby attr_accessible, validates, attr_accessor, cattr_accessor 区别
attr_accessible新建的时候Model里面有一个attr_accessible,从英文全称是attibutes accessible,字面意思是属性可访问比如执行rails g model User name:string email:string,会建立如下的文件并自动添加上attr_accessibleclass User attr_accessib原创 2013-11-05 15:39:38 · 5165 阅读 · 0 评论 -
10个最未充分利用的ActiveRecord::Relation法
在这里,我已经收集了十大最未被充分利用的关系方法从该列表中您的阅读喜悦。10. first_or_create 使用 first_or_createBook.where(:title => 'Tale of Two Cities').first_or_create通常情况下,你想找到一个记录的某些属性,或创建一个与这些附加属性。要做到这一点简洁,您可以提翻译 2013-10-18 09:39:11 · 2842 阅读 · 0 评论 -
使用 Ruby 解析CSV文件&YAML文件
图haml (students.csv文件位置在在public/csv_demo/students.csv).page-model-form .page-admin-form-info .desc 请先下载 CSV 示例文件,按照给定格式填充数据,然后上传导入 %a.download{:href=>'/csv_demo/students.c原创 2013-10-09 14:57:31 · 4214 阅读 · 0 评论 -
Ruby 之Gem kaminari
分页以及查询GemFile# 数据查询gem 'pacecar', '1.5.3' # 给模型添加实用的scopegem 'kaminari', '0.14.1' # 分页支持Modelsscope :like_filter, lambda { |query| if query.blank? { :conditions => ['TR原创 2013-09-26 17:12:20 · 1514 阅读 · 0 评论 -
Ruby之 model.new_record? - parsent?
判读对象是否保存/村有数据 http://api.rubyonrails.org/@model.new_record?原创 2013-09-23 16:49:30 · 1797 阅读 · 0 评论 -
haml f.select
1.f.select.page-survey-form .pblock.form = simple_form_for @survey, :url => '/manage/surveys' do |f| .form-inputs = f.input :title, :input_html => {:class => :xxlar原创 2013-09-23 16:05:28 · 1742 阅读 · 0 评论 -
图表绘制 HTML5
应用:http://www.highcharts.com/demo/pie-basic思路很不错def all_courses_select_apply_pie @courses = CourseIntent.intent_course_ranking stat = { :notfull => 20, :full => 9, :over =原创 2013-09-23 09:55:24 · 2266 阅读 · 0 评论 -
深入理解alias, alias_method和alias_method_chain
对于alias, alias_method, alias_method_chain的深入理解是有益的,因为rails3的源码里很多地方使用了alias_method_chain的魔法。 有人评论说alias_method_chain使用的过多不好,具体怎么不好,是后话了,这篇文章集中在理解这3个方法上面。如果想转载本文,请注明出处,谢谢!请尊重别人的劳动成果,为构建丰富web原创内容做转载 2013-09-18 17:49:06 · 1636 阅读 · 0 评论 -
Passenger/Nginx/Debian快速部署Rails
安装所需的linux包sudo apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libxml2-dev libxslt-dev autoconf libc6-dev zli翻译 2013-09-11 17:58:05 · 2493 阅读 · 0 评论 -
Ruby 元编程 编写代码的代码
1.Kernel#eval2.0.0p247 :428 > array = ['10','20'] => ["10", "20"] 2.0.0p247 :429 > element = '30' => "30" 2.0.0p247 :430 > eval('array << element') => ["10", "20", "30"] 2.0.0p247 :431 >原创 2013-09-08 20:59:00 · 845 阅读 · 0 评论 -
Ruby 元编程 类定义
1.类实例变量 2.0.0p247 :342 > class MyClass2.0.0p247 :343?> @my_var = 12.0.0p247 :344?> def self.read2.0.0p247 :345?> @my_var2.0.0p247 :346?> end2.0.0p247 :347?> 2.0.0p24原创 2013-09-08 15:48:30 · 1146 阅读 · 0 评论