Ruby China
  • 社区
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • 注册
  • 登录
JustQyx
@hz_qiuyuanxin
高级会员
第 2099 位会员 / 2012-05-06

[email protected]
DJI
深圳
22 篇帖子 / 614 条回帖
12 关注者
46 正在关注
195 收藏
教育的目的,不是培养人们适应传统的世界,不是着眼于实用性的知识和技能,而要去唤醒学生的力量,培养他们自我学习的主动性,抽象的归纳力和理解力,以便使他们在目前无法预料的种种未来局势中,自我做出有意义的选择
打赏作者
GitHub Public Repos
  • affirm-ruby 1

    Ruby client library for integrating with Affirm financing payments

  • elasticsearch-with-ik 1

    Just some packages, not a project

  • gfwlist 1

    The one and only one gfwlist here

  • aliyun-oss-ruby-sdk 0

    Aliyun OSS SDK for Ruby

  • pdf_handler 0

    Replace text in pdf

  • ruby_torna_sdk 0

  • RSSHub 0

    🍰 Everything is RSSible

  • justqyx.github.io 0

  • node-torna-sdk 0

  • haoel.github.io 0

More on GitHub
  • 概况
  • 话题
  • 回帖
  • 收藏
  • 正在关注
  • 关注者
  • 我对待技术学习的态度 at 2014年05月18日

    Nice!

  • 重构真是件体力活 at 2014年05月18日

    对于系统来说,重构只要一个标准,那就是不能出错也不能遗漏。 对于人来说,需要去考量输入(即消耗的资源,如时间)与输出,并且很多时候,代码具有很强的主观性,你所认为好的代码对于其他人来说也许并不完全是。

  • 关于 rails 中 helpers 的作用域问题。 at 2014年05月12日

    其实你可以在 helper 里面写个 binding.pry,然后看一下 self,你会发现它的 context 其实就是 ActionView

  • 求教哪款所见所得编辑器比较适合与 Rails 结合在一起用? at 2014年05月02日

    我试过很多编辑器,但是最终还是选择了 CKEditor,因为人家做了很久,稳定强大。

  • 求教哪款所见所得编辑器比较适合与 Rails 结合在一起用? at 2014年05月01日
    • vim
    • sublime text
    • textmate
  • 请教 ActiveRecord 高手 at 2014年04月30日

    #15 楼 @lotusroot 我不是高手,这是数据库基础,AR 只是一个 ORM,提供了一套 DSL

    分页跟你用什么没有关系,

    至于分页插件,现在比较流行的是 kaminari,通过 AR 的 DSL,你可以直接这样

    Order.join("LEFT OUTER JOIN products ON (products.id = orders.product.id)")
      .join("LEFT JOIN stores ON (stores.id = orders.store_id)")
      .select("stores.store_name AS store_name")
      .select("products.product_name AS product_name")
      .select("SUM(orders.rmb AS amount)")
      .group("stores.store_name, products.product_name")
      .order("stores.store_name DESC, products.product_name DESC")
      .page(params[:page])
      .per(30)
    

    而如果自己写 SQL,然后用 ActiveRecord::Base.connection.execute 的话,你需要自己在 SQL 里管分页,而页面的显示,可以参考一下我最近写的博文 Custom Pagination in Rails Use Kaminari

  • 请教 ActiveRecord 高手 at 2014年04月29日

    #13 楼 @lotusroot 你理解错 ActiveRecord 的 includes,好好看看这里的文档

    你应该这样

    Order.join("LEFT OUTER JOIN products ON (products.id = orders.product.id)")
      .join("LEFT JOIN stores ON (stores.id = orders.store_id)")
      .select("stores.store_name AS store_name")
      .select("products.product_name AS product_name")
      .select("SUM(orders.rmb AS amount)")
      .group("stores.store_name, products.product_name")
      .order("stores.store_name DESC, products.product_name DESC")
    

    而且,按照你这个需要来看,根本就不是 Order 该管的事情,你应该直接写 SQL

    report = ActiveRecord::Base.connection.execute <<-EOF
    SELECT stores.store_name AS store_name,
      products.product_name AS product_name,
      SUM(orders.rmb) AS amount
    FROM orders
    LEFT JOIN products ON (products.id = orders.product_id)
    LEFT JOIN stores ON (stores.id = orders.dim_store_id)
    GROUP BY stores.store_name, products.product_name
    ORDER BY stores.store_name DESC, products.product_name DESC
    EOF
    
    report.to_a.each do |row|
      puts "#{row["store_name"]} - #{row["product_name"]} - #{row["amount"]}"
    end
    

    又或者去建一个 VIEW

    最后一点:能看一下写 markdown 的语法么?代码应该用什么包起来?

  • 请教 ActiveRecord 高手 at 2014年04月28日

    @saiga @lotusroot

    #4 楼 @plusor 这个我记得如果 as 后面跟的不是存在字段名,rails 会给过滤掉 @saiga 对的,在 rails c 下执行就可以清楚的看到,只返回 Model 存在的字段

    当然不是这样子的,我自己最近写了好多次了

  • [已解决] git push 还要另外设置? at 2014年04月28日

    #8 楼 @chairy11 如果都要人教你手把手怎么做,那么这世界要你何用

  • [已解决] git push 还要另外设置? at 2014年04月28日

    #4 楼 @chairy11

    你应该设置为 simple

    然后你的 develop 要合并 feature/YBY 应该是:

    git checkout develop
    git merge feature/YBY --no-ff
    git push origin develop
    

    楼主好好去看看 git 的文档吧!!

  • [已解决] git push 还要另外设置? at 2014年04月27日

    http://thekaiway.com/2013/07/30/config-your-git-push-strategy/

  • 请教 ActiveRecord 高手 at 2014年04月27日

    模型的字段,是由其查询后的结果动态生成的,也就是说:如果你返回了 a b c 三个字段,那它即有 a b c 三个方法,而在另一个地方,你返回了 a b c d 那么它就拥有了 a b c d 四个方法。

    A.select("table_a.a, table_a.b, table_a.c")
      .select("table_b.d")
    

    另外,你可以自己写 SQL 语句来做复杂的查询

    result = ActiveRecord::Base.connection.execute <<-EOF
      select table_a.a, table_a.b table_a.c, table_b.d, sum(column) as xxxx
      from table_a
      inner join table_b on (.......)
    EOF
    

    还可以写视图,然后建一个 model 来跟它对应

    class Report < ActiveRecord::Base
      self.table_name = 'xxxx_view'
    end
    
  • 为什么好多 rails 项目的 html 采用 slim,例如 peatio. at 2014年04月24日

    写的人挺爽的,后来维护的人天天问候前面写的人

  • 求助:双数据库双时区的问题 at 2014年04月22日

    #8 楼 @5swords 主要就是个体力活啊! 因为 AR 没办法同时支持两个 timezone,所以还是分开了,算是一种尝试吧。 目前的项目还是允许这么做的。期待能有更好更轻松的解决方案。 你也可以试试直接把 PG 的时区设置成跟 MySQL 一样的,然后检查一个所有日期字段,做必要的数据迁移。这也许是个比较简单直接的方法了。

    @emanon 确实,把 PG 的时区设置成 UTC,然后检查迁移好数据是个比较直接轻松的办法。 两个 ORM 并行也许是个不好的方案,算是走点弯路碰碰南墙也未尝不可。

  • 求助:双数据库双时区的问题 at 2014年04月22日

    #3 楼 @5swords 决定用 Sequel 来替换 Source Model 那边的 AR,然后把不兼容的代码全部 Fix 掉。

    但是在自己拼 SQL 代码的时候仍然需要注意时区的问题,因为不经过 ORM 这一层;还有使用它的一套 DSL 的时候,还是要去检查一下究竟有没有帮你自动转换好的。

    https://github.com/jeremyevans/sequel http://sequel.jeremyevans.net/documentation.html http://sequel.jeremyevans.net/plugins.html http://rosenfeld.herokuapp.com/en/articles/2012-04-18-getting-started-with-sequel-in-rails

    # config/initializers/setup_sequel.rb
    connection = ActiveRecord::Base.configurations["source_#{Rails.env}"]
    
    connection["logger"] = [
      Rails.logger,
      Logger.new("log/source_#{Rails.env}.log")
    ]
    
    Sequel.application_timezone = :local
    Sequel.database_timezone = :utc
    
    Sequel::Model.db = Sequel.connect(connection)
    Sequel::Model.db.sql_log_level = Rails.application.config.log_level || :info
    
  • 求助:双数据库双时区的问题 at 2014年04月22日

    #3 楼 @5swords

    另外对于 PostgreSQL 来说,数据库的 timezone 和当前 session 的 timezone,你在进行操作的时候,PostgreSQL 是会对其进行处理的,而 MySQL 是不管的。

    这个我是自己在两个数据库里测试出来的结果。

  • 求助:双数据库双时区的问题 at 2014年04月22日

    #1 楼 @5swords 思路就是在显示和查询的时候,自己手动去转。

    参杂着自己写,同时又不舍得 ORM 这样是很容易出现人为上的错误的, 要么就统一自己写 SQL 并且结果自己处理,不交给 ORM 处理, 要么就把这问题彻底解决掉,然后都交给 ORM 去处理。

    另外对于 PostgreSQL 来说,数据库的 timezone 和当前 session 的 timezone,你在进行操作的时候,PostgreSQL 是会对其进行处理的,而 MySQL 是不管的。

  • 分享一些我在使用中的 SublimeText 插件 at 2014年04月18日

    Erb 我用的是 Erb Snippets

  • 请教如何拦截 url at 2014年04月18日

    监听下载链接事件,先异步发个请求到后台服务器,然后不要 e.preventDefault()

  • 该怎么开始读 ruby-china 的源码 at 2014年04月15日

    逻辑决定代码,所以你可以分为几块,登录的逻辑、社区板块的逻辑等等

  • Capistrano 3 实现 Rails 自动化部署 at 2014年04月15日

    不爽的一点就是,在 current 目录,它把版本管理给移除掉了。

  • no such file to load -- spreadsheet (MissingSourceFile) at 2014年04月15日

    #6 楼 @yangman_wenzhu 那重新 build 你的 ruby 吧 😂

  • no such file to load -- spreadsheet (MissingSourceFile) at 2014年04月14日

    #2 楼 @yangman_wenzhu 你这回复里贴的图,不是已经 require 成功了么?

  • SaaS 服务里,显示的按 “公司” 信息进行显示的,有没有什么优雅的解决方案? at 2014年04月14日

    #9 楼 @QueXuQ Thread.current 这种做法,本质也是用全局变量的方式。

  • no such file to load -- spreadsheet (MissingSourceFile) at 2014年04月14日

    重新安装一遍试试,我本地在 irb 里试了一下,没有问题

  • SaaS 服务里,显示的按 “公司” 信息进行显示的,有没有什么优雅的解决方案? at 2014年04月13日

    #4 楼 @pynix 能否再详细点,或者给个资料?我也想研究一下这种问题

  • RJS 有什么明显的危害么? at 2014年04月13日

    本质上,其实都是执行 JS 代码。

    如果用了 RJS,虽然说,能够很方便地直接根据逻辑然后执行相关的 JS 代码, 但是这样会把原本应该在同个地方的代码拆分出来了。 你要看什么逻辑,还必须得到模板里去看, 这个跟把代码逻辑直接全部交由前端 JS 代码还是有区别的, 逻辑不会太多还好,逻辑要是多了,那代码阅读起来就比较困难了,更别说维护代码了。

  • SaaS 服务里,显示的按 “公司” 信息进行显示的,有没有什么优雅的解决方案? at 2014年04月13日

    #3 楼 @billy 谢谢提醒,确实存在这样的问题。

  • SaaS 服务里,显示的按 “公司” 信息进行显示的,有没有什么优雅的解决方案? at 2014年04月13日
    def current_company
      # @current_company = current_user.company
      # 换成下面会更好
      @current_company ||= current_user.company
    end
    

    其他地方直接调用 current_company 而不是 @current_company

    建议不要直接改写 model 的 default_scope,直接写个 concerns,然后让 ActiveRecord::Base 去 include 它就好了

    module CurrentCompany
      extend ActiveSupport::Concern
    
      module ClassMethods
        def on_company(company)
          where(company_id: company.id)
        end
      end
    
    end
    
    ActiveRecord::Base.send :include, CurrentCompany
    
  • 更改 link_to 文字颜色 at 2014年04月08日

    https://github.com/twbs/bootstrap-sass/blob/master/vendor/assets/stylesheets/bootstrap/_buttons.scss

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