rails 本地 production 静态文件无法访问

Posted by wxianfeng Sun, 08 May 2011 11:21:00 GMT

环境:
rails3.0.6 + ruby 1.9.2

前面说我 服务器上文件 导出有问题 , 想在本地测试 , 本地开启production , 发现所有的 静态文件都不显示 , 原来是 rails production.rb 配置了 rails 不处理 静态文件 , 在生产环境中都交给了 nginx 等web server 处理了。。

所以你本地没有 nginx 环境 , 直接

>rails s -e production 起的话 

需要 开启 rails 处理public 下处理静态文件的功能:

  # production.rb
  config.serve_static_assets = false

把 false 改为 true


Rails3 production 下导出文件为空

Posted by wxianfeng Sun, 08 May 2011 07:28:00 GMT

环境:
ruby 1.9.2 + rails 3.0.6 + ubuntu 11.04 + centos 5.5

最近一个项目 在本地导出 excel 都没有问题 ,可是上了服务器 导出全部是 空 0 bytes , 原来是因为我部署在nginx 上 ,rails project 需要 配置使用 nginx的send-file 功能 ,

修改production.rb:

 # For nginx:
config.action_dispatch.x_sendfile_header = X-Accel-Redirect

prodcution.rb 中默认的 send_file 配置使用的是apache ,lighttpd 的 配置 , 即 X-Sendfile , nginx的话, 需要使用上面配置

这样导出就没有问题了!!

SEE:

http://stackoverflow.com/questions/3724853/rails-sends-0-byte-files-using-send-file


rails3 autoload_paths

Posted by wxianfeng Thu, 24 Feb 2011 02:23:00 GMT

环境:ruby 1.9.2 + rails 3.0.3

rails3里 autoload_paths 到底有什么用,什么情况加到 autoload_paths 中 ,什么时候使用require? , rails 2.X 里是 load_paths , 例如 rails3里添加 文件夹到 autoload_paths

config.autoload_paths += %W(#{Rails.root}/lib) # 不包括子文件夹

然后 代码里

include AuthenticatedSystem  

就会从 autoload_paths 中寻找 authenticated_system.rb , autoload_paths 和java中的classpath类似 。。

所以没有必要把所有额外的 .rb 文件 都require 一下 , 这样会 影响启动时间 , 但是有些情况是必须 require 的 ,例如扩展 String ,Array ,Hash 类时 就必须require 了

autoload_paths 默认加到了 $LOAD_PATH 全局数组变量中 ,或者写成 $: , 用来保存 paths

autoload_paths 源码 : here

see:

http://errtheblog.com/posts/3-organize-your-models