Monthly Archives: 九月 2013

Capistrano restart Passenger Server

desc “Restart Application” task :restart do run “touch #{current_release}/tmp/restart.txt” end

Posted in ruby on rails | Tagged , | Leave a comment

如何快速有效的租到满意的房子

我也有个题外话 这不是钱的问题 而是被中介忽悠很不爽 可能我思维有点程序化 我是认真看了那些 房源以后 挑了又挑敲定了才打电话过去 结果那边说有有有 然后等你到了又说给别人弄去了 给你推荐 别的房子 对这种中介 我是十分痛恨 从现在的市场环境来讲,中介的最佳策略就是放一个质量好,报价低于市场的房源到网上去,然后等着你电话来了再拿其他的房源推销。这样才能保证吸引足够的关注度,同时成交的利润够高。 而且如果你真的对房源信息研究得足够仔细的话,你会发现同一个房源的几张照片经常是对不上的,所以你如果知道是中介的房源,仔细研究网上的信息根本没有任何必要——因为中介本身根本就不在乎写的信息准不准——他只是想让你给他打电话而已。 如果你不介意通过中介找房,我的建议是把自己当一回甲方,让中介跟着你的脚步走: 1、按区域搜几个房源,看看房子档次差不多,就直接给中介打电话; 2、别管那套房子还有没有,第一问他是哪家中介,然后告诉他你要哪一带的房子,什么样的装修,大概多大面积,什么样的户型,最好是几几年的房子,电器家具是否有要求,甚至能指定哪个小区,什么价位以下,最后记得加一句,你看看有没有合适的房子,有的话给我打电话,没有的就不用找我了; 3、接几个电话你就知道中介靠不靠谱,靠谱就可以多沟通,不靠谱的直接说已经定了; 如果最后必须要付中介费,起码享受一下人的服务之后再付钱,感觉会比较划算一点吧? 网上房子信息真少假多,以网上的信息为基准,说实话有点不靠谱

Posted in Internet | Leave a comment

config.threadsafe! Rails 中的多进程和多线程(翻译)

原文写在 Rails 3时代,目前 Rails 4已经去除 config.threadsafe!,默认已经是线程安全的。 CONFIG.THREADSAFE!: WHAT DOES IT DO? def threadsafe! @preload_frameworks = true @cache_classes = true @dependency_loading = false @allow_concurrency = true self end Preloading Frameworks The first option @preload_frameworks does pretty much what it says, it … Continue reading

Posted in ruby on rails | Tagged , , | Leave a comment

捕获 ActiveRecord::RecordNotFound 输出 404 页面

class ApplicationController < ActionController::Base protect_from_forgery with: :exception rescue_from ActiveRecord::RecordNotFound, with: :render_404 protected def render_404 render(file: “#{Rails.root}/public/404.html”, :layout => false, :status => 404) end end

Posted in ruby on rails | Tagged , , | Leave a comment

Rails 4 Tip

RAILS_ROOT 被 Rails.root 替换 ActiveRecord 的 White list attributes 被 Strong Parameters Gem 替换 如果使用了 accepts_nested_attributes_for 应当如下使用 `Strong Parameters` Class User accepts_nested_attributes_for :profile end # strong parameters params.require(:user).permit(:name, profile_attributes: [:xxx, xx])

Posted in ruby on rails | Leave a comment

CarrierWave README

安装 安装最新稳定版 [sudo] gem install carrierwave 下面代码加入 Gemfile gem ‘carrierwave’ 重启 server CarrierWave 0.5 不兼容 Rails 2,如果你使用的是 Rails 2,请使用 github 仓库中的 CarrierWave 0.4-stable 分支 开始使用 生成一个 uploader rails generate uploader Avatar 将会生成下面文件 app/uploaders/avatar_uploader.rb 使用 uploader 类接收和保存文件 uploader = AvatarUploader.new uploader.store!(my_file) … Continue reading

Posted in ruby on rails | Tagged | Leave a comment

Ruby 生成随机唯一字符串

Time.now.utc.to_i.to_s + ‘-’ + Process.pid.to_s + ‘-’ + (“%04d” % rand(9999)) 随机性可能不太好,唯一没问题

Posted in ruby on rails | Tagged , | Leave a comment