Ruby China
  • Topics
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • Sign Up
  • Sign In
Yuan Cheung
@zhangyuan
VIP
NO. 140 / 2011-11-20

北京
6 Topics / 558 Replies
10 Followers
0 Following
32 Favorites
I'm not the only one.
GitHub Public Repos
  • google-authenticator-e... 10

    A command line tool to extract secrets from Google Authenticator's QR code. 从 Google Authenticato...

  • proxymanager 2

    A simple tool to manage v2ray process and network proxy on MacOS

  • zender 1

    Compile templates written in Jinja, with metadata generated.

  • seo-helper 1

    A simple tool to generate SEO meta info with LLM.

  • dq 1

    A data quality check utility

  • amlogic-s9xxx-openwrt 0

    Support for OpenWrt in Amlogic, Rockchip and Allwinner boxes. Support a311d, s922x, s905x3, s905x...

  • securebin 0

    A simple application for sharing text securely with client side encryption.

  • git-server 0

    A simple demo for git server

  • qqwry-rs 0

    A library and program for IP address lookup using the qqwry.dat file.

  • stm32f103c8t6-blink-ar... 0

More on GitHub
  • Overview
  • Topics
  • Replies
  • Favorites
  • Following
  • Followers
  • In Rack, what is env ['SCRIPT_NAME'] ??? at March 03, 2012

    Rack 中貌似没有PATH这个东东。楼主的意思是系统环境变量里的PATH么?

    Rack 中 env['SCRIPT_NAME']的解释是:

    ## <tt>SCRIPT_NAME</tt>:: The initial portion of the request
    ##                        URL's "path" that corresponds to the
    ##                        application object, so that the
    ##                        application knows its virtual
    ##                        "location". This may be an empty
    ##                        string, if the application corresponds
    ##                        to the "root" of the server.
    

    PEP333 也是这么说的。还有一个解释是

    the “base” of the URL, representing the root of the application.`

    觉得这就是 App 启动后,URL 里的前缀。也可以说是项目的挂载路径吧。


    比如,如果 config.ru 中为

    run MyApp::Application
    
    1. 默认启动,首页地址为 http://locahost:3000/ , env['SCRIPT_NAME'] 的值为空 。
    2. 启动时加上--prefix=/p1参数(比如 thin start --prefix=/p1),首页地址为 http://localhost:3000/p1/ ,env['SCRIPT_NAME'] 的值为 '/p1'。

    如果在config.ru中,写

    map '/p2' do
      run MyApp::Application
    end
    
    1. 默认启动,首页地址为 http://localhost:3000/p2/,那么 env['SCRIPT_NAME'] 的值就是 '/p2' 。
    2. 如果以类似 thin start --prefix=/p1 命令启动,首页地址为 http://localhost:3000/p1/p2/ ,那么 env['SCRIPT_NAME'] 的值就是 '/p1/p2' 。
  • rails 中 最近来访 功能的实现 at March 01, 2012

    可以把必要的信息(比如 user_id, visited_at 等)保存成 JSON 格式,放在某个字段里。然后重写一下这个字段的 writer 和 reader 方法。使用 JSON 的话,可以让其他语言也能读取。

    rails 3.2 里 ActiveRecord::Store 的 store,就是把一些属性序列化后保存的。

  • 如何卸载 Nginx at March 01, 2012

    Nginx 和 Apache 可以同时安装啊。前端用 Nginx 监听 80 端口,处理静态文件;剩下的请求再交给 Apache 去处理。Apache 用其他端口,Nginx 做反向代理。

  • 如何解决 fixtures 数据量很大的时候,数据内容的关联性问题 at February 29, 2012

    factory_gril +1

  • mac 上读 ruby 源代码有什么好工具推荐么? at February 29, 2012

    #15 楼 @lb563 我一同事说,Rubymine 4 比之前的版本快多了。

  • 关于 + 和 << 操作符 at February 29, 2012

    可以使用 #object_id 方法来看是否是一个对象。

    与大多数语言不同,Ruby 的字符串是可变对象。<<在原来的对象上操作,+ 返回新对象。效率如何,可以写 benchmark 看看结果。

  • 关于 callback, 使用 observer 还是写 model 里呢? at February 28, 2012

    个人看法:

    • 如果只更新自己,那么写在 model 里
    • 如果涉及其他模型,那么写在 observer 里
    • 如果要清除缓存,放在 sweeper 里

    具体问题具体做,不绝对哈。不过这种 callback 不要太多,要不然多了以后太难维护了。

  • 讨论关于桌面 (C/S) 应用开发? at February 28, 2012

    Qt 呢?

    豆瓣也有一个桌面库 onering-desktop ,后端是 web,前端是 css+js。具体没用过,仅供参考。

  • mac 上读 ruby 源代码有什么好工具推荐么? at February 26, 2012
    1. ctags
    2. ctags 找不到的,用 grep 搜;也可以用 ack 等
  • 周末午夜瞎扯淡之——哇靠,这真是他的代码?! at February 24, 2012

    或许人家是那种不写代码的 lead dev, 项目经理,CTO ⋯⋯

  • 怎么操作才能使数据库中表记录的 id 从 100 万开始 at February 24, 2012

    1 楼的帖子里不是说了么⋯⋯但是我没有验证,因为不用 postgresql。SQL 语句是

    ALTER SEQUENCE table_name_id_seq RESTART WITH 1000000;
    
  • 为什么在 rails 项目中 touch /tmp/restart.txt 这个文件就可以达到更新服务的目的? at February 24, 2012

    #3 楼 @zfjoy520 监控文件有个 gem fssm ( https://github.com/ttilley/fssm ,File System State Monitor),针对不同的系统和系统现有的 gem,使用不同的 backend

  • 無法安裝 REE at February 24, 2012

    参见 http://ruby-china.org/topics/834 帖子和回复。

  • 怎么操作才能使数据库中表记录的 id 从 100 万开始 at February 24, 2012

    http://stackoverflow.com/questions/5440401/change-autoincrement-values-in-migration-postgresql-and-sqlite3

  • 为什么在 rails 项目中 touch /tmp/restart.txt 这个文件就可以达到更新服务的目的? at February 22, 2012

    nginx -s reload 是重启 Nginx touch /tmp/restart.txt 是重启当前的 Rails 项目

    Passenger 会检查这个文件,如果这个文件时间戳改变了,或者被创建或者移除,Passenger 就会 reload。

    相关的实现可以在 passenger 代码中查看 needsRestart 这个函数:

    https://github.com/FooBarWidget/passenger/blob/master/ext/common/ApplicationPool/Pool.h

  • rails 调试时如何将结果输出到 console?[已解决] at February 22, 2012

    把默认的 logger 改成 Logger.new(STDOUT),比如

    ActiveRecord::Base.logger = Logger.new(STDOUT)
    ActiveResource::Base.logger = Logger.new(STDOUT)
    ActionController::Base.logger = Logger.new(STDOUT)
    
  • 我来破处。。。 问个更新空值到 int 列的问题 at February 21, 2012

    projectID 的类型是什么呢?

  • ruby on rails 的老手们,能帮我出个多个环境开发多个项目的主意吗? at February 19, 2012

    如果是用 rvm+passenger 的话,可以在 nginx 里配置一个 rails 项目以普通方式运行,然后其他的项目使用 passenger standalone 方式运行,在 nginx 配置 Proxy。

    官方文档 Phusion Passenger & running multiple Ruby versions 可供参考。

  • 在 rails 怎么把一个后缀名为.swf 或者.jpg 转换成相应的 html 标签 at February 19, 2012

    正则?

  • 论坛里面可以用 Markdown 语法了 at February 18, 2012

    把帖子内容里的 h1-h6 设置成一个样式,这样就不会影响排版了吧?

  • centos yum intall 为什么会安装 i386 和 x86_64 两种类型的包? at February 17, 2012

    #1 楼 @jinleileiking OS 是 CentOS,看标题⋯⋯

  • Ruby 1.9.3-p125 is released at February 17, 2012

    #6 楼 @hhuai 哈哈,我以前都是重新创建 gemset 再安装 gems。刚才看了一下,还有 rvm gemset copy ruby-1.9.3-p0@rails3 1.9.3-p125@rails3 这个命令。

  • Ruby 1.9.3-p125 is released at February 17, 2012

    #3 楼 @hhuai

    rvm get stable
    rvm install 1.9.3
    
  • Rails route 匹配的问题 at February 16, 2012

    路由里的 id,只是参数的 key 的名字,不一定非得是整数。

    另外,Rails-2.3.5 的相关代码在 ActiveRecord::ConnectionAdapters::Quoting#quote 。如果这个字段,在数据库里的字段类型是 integer,那么拼 SQL,会先把值 #to_i;如果是 float,那就是 #to_f:

    elsif column && [:integer, :float].include?(column.type)
      value = column.type == :integer ? value.to_i : value.to_f
      value.to_s
    

    column 是数据库的字段;value 是字段值。

  • Rails route 匹配的问题 at February 16, 2012

    这是个 feature。

    PS:有一些站点为了 SEO 或者其他目的,把 title 放在 url 中(这个叫 slug 吧?),使用的是 http://localhost/posts/123-hello-world 这种形式。reddit 的评论地址是 http://www.reddit.com/r/pics/comments/:id/ ,也可以是 http://www.reddit.com/r/pics/comments/:id/:title ,这个 title 一般是帖子标题,但可以是任意合法的字符串。

  • 关于字符串的 split 问题 at February 15, 2012

    信息太少,请贴出足够的代码

  • Prev
  • 1
  • 2
  • …
  • 15
  • 16
  • 17
  • 18
  • 19
  • Next
关于 / RubyConf / Ruby 镜像 / RubyGems 镜像 / 活跃会员 / 组织 / API / 贡献者
由众多爱好者共同维护的 Ruby 中文社区,本站使用 Homeland 构建,并采用 Docker 部署。
服务器由 赞助 CDN 由 赞助
iOS 客户端 / Android 客户端 简体中文 / English