Ruby China
  • Topics
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • Sign Up
  • Sign In
Rei
@Rei
Admin
NO. 1 / 2011-10-28

[email protected]
深圳
188 Topics / 9160 Replies
731 Followers
0 Following
11 Favorites
中下水平 Rails 程序员
Reward
GitHub Public Repos
  • writings 941

    [Closed] Source code of writings.io

  • alipay 732

    Unofficial alipay ruby gem

  • code_campo 291

    [Closed] Source code of http://codecampo.com

  • asciidoctor-pdf-cjk-ka... 101

    **no longer maintained**

  • geeknote 34

  • asciidoctor-htmlbook 31

    Asciidoctor HTMLBook is an Asciidoctor backend for converting AsciiDoc documents to HTMLBook docu...

  • material-ui 17

  • rich-text-editor 12

  • htmlrenderer 12

  • rails-chatgpt-demo 8

More on GitHub
  • Overview
  • Topics
  • Replies
  • Favorites
  • Following
  • Followers
  • 生产环境的部署问题 at March 21, 2015

    User 类继承了什么类?

  • GitCafe.com 支持 Line Note 了! at March 20, 2015

    这个绿对我有些刺眼。

  • 求助,在公司内网部署 Rails,就几个人用,需要设置成 production 模式吗? at March 20, 2015

    我想不到理由不用 production。

  • Rails 开发:那些年,我们一起踩过的坑 (剧终) at March 20, 2015

    #21 楼 @scriptfans 我自己写的 plugin 是幂等的,如果原插件不幂等就加个 wrapper:

    $(document).on 'page:change', ->
      $('textarea[data-behaviors="editor"]').each ->
        element = $(this)
        if not element.data('editor')
          element.data 'editor', element.editor()
    
  • Rails 开发:那些年,我们一起踩过的坑 (剧终) at March 20, 2015

    #14 楼 @scriptfans

    提供几个模式:

    1. 整站共享的逻辑,例如购物车:

    $(document).on 'click', '.cart', ->
      # code here
    

    2. 特定元素存在的时候触发的逻辑,例如 editor:

    $(document).on 'page:change', ->
      $('textarea[data-behaviors="editor"]').editor() # a jquery plugin
    

    3. 特定元素由用户触发的逻辑,例如 modal:

    $(document).on 'click', '[data-toggle="modal"]', ->
      # toggle modal
    

    4. 某个页面特有的逻辑:

    写到页面末尾,用内嵌形式。

    <script>
      // code here
    </script>
    

    现在不用操心 ready 了,page ready 是 jQuery 带来的思维方式,在 Turbolinks 环境需要另一种思维方式。无论最终是否用 Turbolnks,理解它,就会发现自己对浏览器如何执行 JavaScript 有更深的理解。

    如果是前端开发者,应该比我更熟悉 Ember.js,Angular.js 这些框架,在这些框架生成的页面元素上要怎么操作 DOM 呢?Angular.js 的 FAQ 里面说,不要自己操作 DOM(Stop trying to use jQuery to modify the DOM in controllers.),为了打破习惯,还建议移除 jQuery(If you're struggling to break the habit, consider removing jQuery from your app.),这可不止要改变事件绑定的习惯。现在前端开发者可喜欢捣鼓新玩意了,我不担心他们。

  • Rails 开发:那些年,我们一起踩过的坑 (剧终) at March 20, 2015

    #9 楼 @scriptfans

    某一天,我的 boss 蛋疼说要做桌面版 GUI,在前面的基础上,我可以直接把 service copy 过来用

    #10 楼 @scriptfans

    你不会想前后端重复某些业务逻辑的。

    这不是自相矛盾了么。

    我没有阻止你加 Services 层,mkdir app/services 一条简单命令就实现了,但是在需求没出现的时候就加那么多层只会把问题搞得更复杂。service object 只是 Ruby object,Rails 框架不会也不能阻止你用。

    我 7 楼说的是 js respond,不是 json。不过 json 也一样的,我不会在 html 以外的 respond 写 redirect_to。为什么?因为我测试过,每个 respond format 返回各种内容,例如 js 请求返回 3xx 响应会不会执行,json 请求返回 5xx 响应会不会解析,这在我学习 Rails 的很早阶段、刚知道 respond_to 这个方法的时候就测试过了。干了九年 Rails 开发才总结出这些问题我觉得不是值得炫耀的事。

    顺便说说 js 请求重定向的方法:

    // destroy.js.erb
    
    // with Turbolinks
    Turbolinks.visit('<%= resources_path %>');
    
    // without Turbolinks
    document.location.href = '<%= resources_path %>';
    

    单单为重定向写个模版有点浪费,所以 Turbolinks 3.0 开始给 redirect_to / render 打了补丁,可以直接在 Controller 用 redirect_to / render https://github.com/rails/turbolinks/blob/4e9acc30ded75bb4fd88597b90eadcbf9c809545/lib/turbolinks/redirection.rb

    如果充分理解 Rails 框架,自然可以将它扩展到各个场合,但如果大部分时间是在跟框架对抗,那么应该换框架了。我好奇楼主觉得现在哪个框架最先进?我有空参考一下学习它的长处。

  • Rails 开发:那些年,我们一起踩过的坑 (剧终) at March 20, 2015

    1. 如果你需要可以 mkdir app/services 新建一个 service 层。

    DHH 认为 Controller 就是 service 层,据我了解 DHH 从未建议把所有业务逻辑都写到 Model,所谓充血模型是一些文章一厢情愿。

    要了解更多可以看这篇文章:Keep email views out of the models http://david.heinemeierhansson.com/2012/emails-are-views.html

    2. 我觉得很奇怪,很多人愿意用一个前端框架重写整个应用,却不愿意了解 Turbolinks 的原理。(也许这是两个人群)

    3. 从未在 js respond 写 redirect_to,因为知道这不会跟 http 请求一样响应,没觉得这是个问题。

  • 为什么 Java 没有 GIL? at March 20, 2015

    以我阅读《Seven Concurrency Models in Seven Weeks》第一章了解到的,Java 线程需要程序员处理的问题一样有,然后作者再三强调用锁很容易出错,推荐用其它并发/平行模型。

  • Rails 的本地化语言识别你们都用的什么方式啊? at March 19, 2015

    除非内容经过本地化,不然不推荐用 url 参数(路径或参数),否则搜索引擎会索引很多重复内容。

  • Rails 的本地化语言识别你们都用的什么方式啊? at March 19, 2015
    url 参数 || 用户设置 || Accept-Language Header || default
    
  • 关于用户权限的问题 at March 19, 2015
    @book = current_user.books.find params[:id]
    
  • UJS Ajax 或 JSON Ajax 没有效果 at March 19, 2015
    $.ajax
    type: "POST"
    

    缩进不对。

  • 关于 ruby 控制 window cmd 发 ftp 命令的问题 at March 16, 2015

    我不知道怎么处理你的问题,但我觉得有更好的方法 http://ruby-doc.org/stdlib-2.0/libdoc/net/ftp/rdoc/Net/FTP.html

  • ruby ,_=是什么意思? at March 16, 2015

    某些语言或者检查器中,定义了不使用的变量会报警,于是出现了 _ 标明不使用该变量的语法。

  • 用免费的 Heroku,(paper/carrier)有什么方法可以存图片么?想花几分钟,部署一个玩具。 at March 16, 2015

    七牛有免费档。

  • js 中修改 data-method 无效么? at March 15, 2015

    不知道了,我以前就这样写的 https://github.com/chloerei/campo/blob/master/app/assets/javascripts/plugins/likes.js.coffee

  • js 中修改 data-method 无效么? at March 15, 2015
    ('span ').text('喜欢');
    data("method", "post")
    

    这里 data 的调用对象是什么?

  • js 中修改 data-method 无效么? at March 15, 2015

    打错,attr('data-method', 'post')

  • js 中修改 data-method 无效么? at March 15, 2015

    试用 attr('method', 'post')

  • 做 Ajax 测试时遇到的问题 at March 14, 2015

    Rails Test 本身是包在事务中的,每个 case 后回滚,不需要 DatabaseCleaner 吧?

  • 定义方法后面加 “=”,意义是什么? at March 13, 2015

    楼主没有清楚表达他不明白哪一点,所以回复的人从 Ruby 基础到架构设计都回答了一轮,然后楼主觉得哇怎么这么深奥。

  • "中级 Ruby 工程师"都在做什么? at March 12, 2015

    初级 - 工资比中级低 中级 - 工资比高级低 高级 - 工资比 CTO 低 CTO - 拿着股份顶工资

  • 电脑崩盘引发感慨 at March 12, 2015

    Dropbox 邀请链接

    https://db.tt/tdIsTDAm

    对于加入 Dropbox 并在电脑上安装 Dropbox 的每位朋友,我们会同时为您和这位朋友提供 500 MB 的额外奖励空间(最高上限可达 16 GB)!

  • 为支持移动端离线模式-数据库采用 UUID 字段 at March 12, 2015

    Backbone.js 有类似机制,区分 id 和 client id http://backbonejs.org/#Model-id

    id model.id A special property of models, the id is an arbitrary string (integer id or UUID). If you set the id in the attributes hash, it will be copied onto the model as a direct property. Models can be retrieved by id from collections, and the id is used to generate model URLs by default.

    cid model.cid A special property of models, the cid or client id is a unique identifier automatically assigned to all models when they're first created. Client ids are handy when the model has not yet been saved to the server, and does not yet have its eventual true id, but already needs to be visible in the UI.

  • "中级 Ruby 工程师"都在做什么? at March 12, 2015

    直接去看这个公司在做什么项目。

  • Rails 4.2 版本,执行 rails new project 后一直卡在 run bundle install 那里 at March 11, 2015

    Ctrl-C 中止 bundle,cd 到项目目录,执行 bundle --verbose,如果是卡在网络就翻墙。不是的话贴日志上来。

  • 我喜欢酱紫的 Hash at March 11, 2015
    options =                                         {
      url: "注意!结尾必须写逗号"                         ,
      host: "如果不写逗号,那么会报错"                      ,
      customer:                                       {
        name: "逗号很小, 不明显, 不小心删掉了,都很难发现"    ,
        number: "结尾还有很多括号, 好崩溃呀"               ,
        bills:                                        [{
          number: "苦逼", memo: "苦逼苦逼苦逼苦逼"       },{
          number: "苦逼", memo: "苦逼苦逼苦逼苦逼"       },{
          number: "苦逼", memo: "苦逼苦逼苦逼苦逼"       },]},}
    
  • 怎么设置一个页面编辑完成后跳转的地址? at March 10, 2015

    #6 楼 @gsky 奥,我想明白了。

    get 'factor' => 'factors#new'
    

    这条路由生成了 factor_path 这个命名路由,跟 resources :factor 的单数形式路由冲突了。

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