Ruby China
  • Topics
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • Sign Up
  • Sign In
@vkill
VIP
NO. 120 / 2011-11-17

7 Topics / 294 Replies
4 Followers
0 Following
114 Favorites
No GitHub.
  • Overview
  • Topics
  • Replies
  • Favorites
  • Following
  • Followers
  • rails 用 win32ole 打开 word 问题 at August 13, 2013

    试试 roo 或 spreadsheet 吧

  • Ruby 开发收藏 at July 07, 2013

    +1

  • 一般支持多种页面布局模板的都是什么样的方案? at June 02, 2013

    http://railscasts.com/episodes/269-template-inheritance prepend_view_path 呢?

  • NG 会抢 Rails 的饭碗成为明日之星么? at June 02, 2013

    #14 可以在后端生成好 html 第一次请求的时候返回给前端嘛,没说前端话后端的 view 就完全不用,呵呵

  • 生成前端框架相关 routes 的正确方法是啥? at May 11, 2013

    https://github.com/railsware/js-routes

  • 大家给证件号打马赛克有什么好的代码写法么? at April 04, 2013
    number.gsub(/^(?<h>[\d]{6})([\d]*)(?<t>[\w]{4})$/, '\k<h>XXXXXXXX\k<t>')
    

    这样?

  • wget 怎么覆盖下载 at March 29, 2013

    wget -mk 吧

  • 2009年4月26日的一个下午。。。 at March 26, 2013

    哈哈,好安逸~

  • respond_with 使用上的一些问题 at March 26, 2013

    2 确实是都可以用 respond_with

    下面是一些用法

    这个就是很经典的那种写法的简写

    @message.new(params[:message])
    @message.save
    respond_with @message, :location => [:messages], :action => :new
    

    有 namespance 时

    respond_with :admin, @repository
    respond_with :admin, @repository, :location => root_path
    

    使用嵌套路由时

    respond_with @post, @comment
    

    当然,如果你想自定义 response code 时,使用类似这个方法 https://github.com/nesquena/rabl/wiki/Response-Codes

    如果你想自定义 flash,参考 https://github.com/plataformatec/responders

    配合 respond_to 就可以定义 action 使用 哪些 template

    3 respond_with 后面传递那个 resource 仅仅是用 resource.errors.empty? 来判断成功和失败的

    4 在 search 完成后的 template 里直接用 controller 里的 @xx 就好了,不需要传递

  • 请教多个模型复用 Category 的办法 at March 14, 2013

    就用 category 字段就好了,重复的代码写到 module

  • gitlab-shell for gitlab v5.0 at March 14, 2013

    谢谢 #14 #15 楼 @Saito @bhuztez 兄科普,我只实施过 pam_mysql 和 nss 来用数据库中用户登录。pam 方面的资料确实少,同希望大牛顺道提供。

  • gitlab-shell for gitlab v5.0 at March 14, 2013

    hi @Saito 看了 #6 的回复,现在 gitlab 还是通过修改 authorized_key,指定使用自己的 ssh magic command 用脚本来实现从数据库中匹配 user 和 repo 的关系吧?听了第六期的 http://teahour.fm/2013/03/11/git-github-and-gitlab.html ,再看 #7 #8 回复,这里有个疑问,如果不用 authorized_key,是选择修改 sshd pam 呢?还是选择类似于用 eventmachine 写个 sshd 来实现呢?pam 中如何指定 command 能否给个参考资料呢?谢谢

  • 大家开发项目的时候是如何定义 Gem 的 Version Dependency 的? at January 19, 2013

    开发的时候就仅仅是 require,开发完成后根据 Gemfile.lock 回头再来固定版本 基本上默认最新的都是稳定版本

  • 基本上能给业界流行的开源源件提交 Patch,都会让人对你刮目相看。 at January 19, 2013

    嗯,在理

  • 常见的 JavaScript MVC 框架 at January 19, 2013

    #2 楼 @knwang “Angular 是支持视图排版的”,这个能详细的讲解下吗?

  • 在一个 controller 中调用另一个 controller 中的 action? at January 18, 2013

    TestsController.action(:test).call(env)

    但是这样意义不大,基本上都是在 middleware 和 routes.rb 中这样用,action 中这样调没啥意义。

  • Devise 编辑用户信息 password too short at January 16, 2013

    validates ... :on => :update 注册和更新分开 valid

    更新前需要验证当前密码 devise 有提供 update_with_password https://github.com/plataformatec/devise/blob/master/lib/devise/models/database_authenticatable.rb#L56 方法,需要你提供 params[:current_password],controller 里也就需要使用 update_with_password ,现有的 devise 提供的修改基本信息 https://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb#L39 只要提供当前密码包括 email password 等其他信息都是一起改的。按照你的需求,你得自己定义个新的路由来更改信息,controller 参考 registrations#update 写就 ok 了,可以根据需求使用 update_with_password 和 update_without_password

  • 关于 cache,加载 sweeper 报错 at January 16, 2013

    config.xx 直接 application.rb 里改就是了,为啥在 environment.rb 改呢?

    Rails::Initializer 是不是 Rails::Initializable::Initializer 这个?

  • resque timeout 问题,求助大侠 at January 15, 2013

    换用 sidekiq 呢?代码基本上不用改动。

  • 推荐一本好书<<卓越程序员密码>> at January 15, 2013

    #6 楼 @sailtsao 哈哈,以前周日常去,现在有点点小忙。。。

  • 推荐一本好书<<卓越程序员密码>> at January 15, 2013

    <<简约之美:软件设计之道>> 不晓得这本杂样?

  • 推荐一本好书<<卓越程序员密码>> at January 15, 2013

    感谢推荐,“此书每篇都不长,但是每篇都会让你有所感悟,有所收获”就冲这句,买来品之!

  • Devise 中 resource,和 resource_name 是啥意思 at January 14, 2013

    #5 楼 @evil850209

    resource= https://github.com/plataformatec/devise/blob/master/app/controllers/devise_controller.rb#L92

    resource https://github.com/plataformatec/devise/blob/master/app/controllers/devise_controller.rb#L16

    sign_in https://github.com/plataformatec/devise/blob/master/lib/devise/controllers/helpers.rb#L114

    也就是说 sign_in 的时候会给 "@#{resource_name}" 赋值,当然还有几个地方会对 "@#{resource_name}" 进行修改的,具体的可以搜索下 resource =、resource ||=、resource= 这些

  • 工作中的教训总结,供大家围观 at January 14, 2013

    血泪的教训啊~

  • 请问 Rails 中可以动态创建数据库表或动态在表中添加字段吗?而不是通过 db:migrate at January 11, 2013

    #2 楼 @scige 每个人一个 sqlite,可以使用下面的方法动态生成一个 model 来做数据操作了。建库、建表参考 https://github.com/luislavena/sqlite3-ruby 吧,上面有例子。当然也可以用 migration 来做这个事情。

    require 'sqlite3'
    require 'active_record'
    
    my_ar = Class.new(ActiveRecord::Base) do
      self.abstract_class = true
      establish_connection(
        :adapter => "sqlite3",
        :database  => "/tmp/tmp.sqlite3"
    )
    end
    my_user = Class.new(my_ar) do
      self.table_name = 'users'
    end
    my_user.new
    
    
  • Rails 这次漏洞有点严重啊 at January 10, 2013

    #45 楼 @iBachue User.find_by_id "1 or 1 = 1" 这样生成的 sql 没意义吧?查询结果仅仅和第一个 1 有关系。

  • 请问 Rails 中可以动态创建数据库表或动态在表中添加字段吗?而不是通过 db:migrate at January 10, 2013

    如果只是自己用用,数据量不大的话,每个人一个 sqlite 好了,简单

  • ruby 读取 utf-8 xml,谁知道?1.8.6 at January 10, 2013

    ruby 1.8 是 $KCODE='UTF-8' ,1.9 才是 #encoding: utf-8

    REXML 默认的 encoding 就是 utf-8,所以 xml 应该是 utf-8 的,参考 http://ruby-doc.org/stdlib-1.8.6/libdoc/rexml/rdoc/REXML/Encoding.html

  • 如何在 ActiveRecord 的关联链条中避免重复 touch at January 10, 2013

    当数据库性能发生瓶颈的时候再解决这个问题吧,到时候也仅仅是 去掉 touch: true 加点 after_commit update_all 之类的

  • 加入 twitter bootstrap 以后,找不到 bootstrap_and_overrides.css.less 文件 at January 09, 2013

    你忘记了加 "less-rails" 这个 gem

    group :assets do
      gem "therubyracer"
      gem "less-rails"
    end
    gem "twitter-bootstrap-rails"
    
  • Prev
  • 1
  • 2
  • 3
  • 4
  • 5
  • …
  • 9
  • 10
  • Next
关于 / RubyConf / Ruby 镜像 / RubyGems 镜像 / 活跃会员 / 组织 / API / 贡献者
由众多爱好者共同维护的 Ruby 中文社区,本站使用 Homeland 构建,并采用 Docker 部署。
服务器由 赞助 CDN 由 赞助
iOS 客户端 / Android 客户端 简体中文 / English