gem install和bundle install使用代理proxy

假设本地代理服务器的端口是1080 下面是gem的: gem install nokogiri -v '1.10.9' -p http://127.0.0.1:1080 下面是bundle的: export HTTP_PROXY=http://127.0.0.1:1080 bundle install
2020-06-27 06:41 | 阅读 5318 次 | 评论 0 条

语言是思维的记号

选一个好看点的记号,便于梳理思维,有利于身心健康。 乱糟糟的记号把人的思维都带乱了,以其昏昏使人昭昭,@php
2020-05-20 20:05 | 阅读 642 次 | 评论 0 条

基于纯 ruby 的 XML/HTML 解析器,可替代 nokogiri

https://gitlab.com/yorickpeterse/oga
2020-01-08 11:34 | 阅读 1480 次 | 评论 0 条

passenger设置起始进程数

http { passenger_root /usr/local/lib/ruby/gems/2.3.0/gems/passenger-5.0.30; passenger_ruby /usr/local/bin/ruby; passenger_min_instances 3; //此处设置起始进程数为3 passenger_pre_start http://blog.bccn.net/sessions/seccode_check; passenger_max_pool_size 6;...
2019-09-16 00:13 | 阅读 2036 次 | 评论 0 条

textmate2保存文件时自动删除行尾空格

默认textmate2是没有这个功能的,不过可以通过Bundles开启,开启方法: 1、点击菜单中的Bundles,然后 Edit Bundles 2、在弹出窗口中,依次点击 Text -> Menu Actions -> Converting / Stripping -> Remove Trailing Spaces in Document / Selection , 在最右侧的 Semantic Class 一栏填入:callback.document.will-save ,如图所示: ...
2019-07-27 03:00 | 阅读 1816 次 | 评论 0 条

用docker部署rails应用以后要把log和tmp的权限设置为777

cd到rails的目录,执行 chmod 777 -R log chmod 777 -R tmp
2019-05-28 15:03 | 阅读 1229 次 | 评论 0 条

Rails Model中的enum(枚举)二三事

假设这么一个Model class Order < ApplicationRecord enum type: {'支付宝充值': 1, '微信充值': 2, '后台手工加值':3, '后台手工减值':4, '提现':5, '发布问题减值':6, '答案被选中加值':7} end 那么可以进行下面这些枚举操作,首先是对象的操作 [1] pry(main)> order = Order.first => [2] pry(main)> order.type => "后台手工减值" [3] pry(main)> order.read_attribute_before...
2019-05-24 00:36 | 阅读 1342 次 | 评论 0 条

解决ruby内核参考离线版js文件的引用问题

官方的离线版默认是放在根目录的,所以js引用都是这种形式: <script src="/js/extra.js"></script> 注意红色的反斜线,这样如果不是放在根目录,那么就会出现js引用的错误。 废话少说,用一段ruby代码即可解决: files = `ag 'src="/js' -l`.split("\n") files.each do |f| s = open(f).read if f.scan(/\//).count == 0 s = s.gsub(/\<script\s+src=\"...
2019-05-05 18:55 | 阅读 1725 次 | 评论 0 条

rails命令出现大量 warning: constant ::Fixnum is deprecated 的解决办法

这些警告虽然不影响使用,但看着烦人。按以下方法可解决: which rails 找到rails的路径(我的是 /Users/gs/.rvm/gems/ruby-2.5.3/bin/rails,当然你的和我的可能会不一样),然后: vim /Users/gs/.rvm/gems/ruby-2.5.3/bin/rails 在第一行和注释下面加上: ENV['RUBYOPT'] = '-W0' 这样就可以屏蔽warning了
2019-01-21 00:21 | 阅读 8082 次 | 评论 0 条

rails不能在model中使用type作为字段名的解决办法

使用type作为字段名会出现这个错误: ActiveRecord::SubclassNotFound: The single-table inheritance mechanism failed to locate the subclass: 'xxxx'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to ...
2018-04-01 21:40 | 阅读 3125 次 | 评论 0 条

RubyMine启动时去掉烦人的gem检测失败提示

Appearance &amp; Behavior > Notifications 找到Gem Manager,把log取消掉
2018-03-26 14:24 | 阅读 2154 次 | 评论 0 条

Rails直接更新字段用where ... update_all ...或update_column

不查询数据记录,直接更改 Category.where(id: category_id).update_all(articles_count: articles_count)
2016-11-30 09:31 | 阅读 4364 次 | 评论 0 条

ruby一行定义md5、md5file函数

require 'digest/md5'; def md5(str); Digest::MD5.hexdigest(str); end; def md5file(str); Digest::MD5.hexdigest(File.open(str).read); end 在pry中用的时候很方便
2016-10-31 01:18 | 阅读 2356 次 | 评论 0 条

ruby生成随机字串

(0...50).map { ('a'..'z').to_a[rand(26)] }.join
2016-02-24 16:17 | 阅读 12710 次 | 评论 0 条

rvm全局(global)安装gem

rvm 2.2.1@global do gem install phantomjs
2015-08-03 15:01 | 阅读 3201 次 | 评论 0 条

rails清理assets缓存的方法

刚才development环境下 sass 中的 image_url 失效了,运行下面的命令清空缓存解决: rake assets:clobber
2015-07-22 15:12 | 阅读 3464 次 | 评论 0 条

ruby遍历文件夹

已经不需要自己写递归了,新版ruby直接提供了Find模块 require 'find' Find.find('./') do |path| puts path end
2015-07-22 10:50 | 阅读 4984 次 | 评论 0 条

rails用generate为两个模型创建has_and_belongs_to_many中间表

Where: class Teacher < ActiveRecord::Base has_and_belongs_to_many :students end and class Student < ActiveRecord::Base has_and_belongs_to_many :teachers end for rails 4: rails generate migration CreateJoinTableStudentTeacher student teacher for rail...
2015-06-30 09:57 | 阅读 5002 次 | 评论 0 条

capistrano列出所有命令(task)

cap -T
2015-05-06 21:14 | 阅读 2406 次 | 评论 0 条

ruby类获取所有非继承方法的方法

Model.instance_methods(false) 如果获取包含继承的方法,后面的参数则改为 true
2015-04-27 11:41 | 阅读 3588 次 | 评论 0 条
浏览2776831次
文章归档