楼主的解决问题能力非常强。
对于邮件的 HTML, 只是内联样式,还有许多样式并不支持。
Rails4.1 很给力,写 mailer 已经很方便了。
可以 goolge 下 : rails engine
不错的解决手段。
有点觉得 Update 解决的不太优雅。
#3 楼 @gerry1004 那个库有 bug, 试试这个:
gem 'rqrcode-with-patches', require: 'rqrcode'
完整代码示例:
class QrcodesController < ApplicationController
def show
str = params[:str].to_s
max_length = 200
if str.length > max_length
render nothing: true, status: 404
return
end
require 'rqrcode/export/png'
qr = RQRCode::QRCode.new(str)
response.headers['Cache-Control'] = "public, max-age=#{12.hours.to_i}"
response.headers['Content-Type'] = 'image/png'
response.headers['Content-Disposition'] = 'inline'
render :text => qr.as_png
end
end
代码从开源项目 wblog 取出。
def getgood
good = TaoBaoApi::Good.new params[:buy_link]
item = good.get_info
# 只有 json 的数据 前端才能到回调里
render :json => { :find => "NO",:data =>item}
end
如果你用的是 Ruby2.0 以上,可以尝试手动改一下字串的计算方式如下:
str = '中文'
str.length
# result is 2
str.encode('gbk').force_encoding('ascii').length
# result is 4
查看源代码嘛。JS 里直接写好了分数。
@zhangyuan 嗯,刚 pry 跟了下,确实是线程安全的:
# From: /Users/yafeilee/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/logger.rb @ line 558 Logger::LogDevice#write:
557: def write(message)
=> 558: begin
559: @mutex.synchronize do
560: if @shift_age and @dev.respond_to?(:stat)
561: begin
562: check_shift_log
563: rescue
564: warn("log shifting failed. #{$!}")
565: end
566: end
567: begin
568: @dev.write(message)
569: rescue
570: warn("log writing failed. #{$!}")
571: end
572: end
573: rescue Exception => ignored
574: warn("log writing failed. #{ignored}")
575: end
576: end
不保证,默认情况下 Rails 只是用 Ruby 自带的 Logger 库来记录日志。
你可以自行修改 config/environments/production.rb 里面的 logger 来达到你的要求。
#5 楼 @xifengzhu 如果是我招人的话,也会对此加分的。并不是说用它们就高端,而是从侧面说明用它的人是真正热爱 coding.
#43 楼 @blackangel_can 里面有提了一句。
学到 Hash#fetch
begin resuce -> begin rescue
给客户端要求的话它爆破起来就慢很多了。
就这几个思路,很多系统都是结合着用,先限制,最后一步觉得用户还有风险才会启用验证码。
( ps: 我记得验证码在 google 的一个智能识别系统上被完破了 )
@chrisloong devise 有一个 lockable 模块和 timeout 模块,直接支持这种限制次数与锁定的模式。
直接上验证码感觉有点粗暴了,毕竟体验会下降不少。
#27 楼 @ninehills 作为 "高手" 怎能轻易服输 , 不能老使用大招。
#32 楼 @chrisloong 赞一个~
#6 楼 @ninehills 部分虚构,让你误解了。不过这个故事其实跟 ssh 暴破没任何关系。
@Rei 那只是一个错误之一。
@yangman_wenzhu 尝试找一个低版本的安装即可。比如 gem install nokogiri --version 1.5.6

香港这个果然有特色:超小的空间:)
#5 楼 @nightire 我觉得凡事就是多探讨才有提高,所以发出文章来看看大家的理解。
#6 楼 @feitian124 发现已经前不久就关注了:) 我并没有厚此薄彼,会继续关注这个领域的发展。
" 1 tab to 2 space for ruby
set tabstop=2
set softtabstop=2
set shiftwidth=2
set expandtab
see more: https://github.com/windy/ruby-vimrc
友情支持:)