Ruby China
  • 社区
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • 注册
  • 登录
Rei
@Rei
管理员
第 1 位会员 / 2011-10-28

[email protected]
深圳
182 篇帖子 / 9132 条回帖
727 关注者
0 正在关注
11 收藏
中下水平 Rails 程序员
打赏作者
GitHub Public Repos
  • writings 940

    [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**

  • 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

  • rails-app 7

    A Rails project template lets me start new projects quickly.

More on GitHub
  • 概况
  • 话题
  • 回帖
  • 收藏
  • 正在关注
  • 关注者
  • [求助] Rails 5.2 多重多态怎么获取正确的 url? at 2018年08月23日
    class Report
      # 安全原因,阻止用户提交预料外的东西
      validates :reportable_type, inclusion: { in: %w(Comment) }
    end
    
    new_reports_path(reportable_type: 'Comment', reportable_id: @comment.id)
    
    def new
      @report = Report.new report_params
    end
    
    def create
      @report = Reports.new report_params.merge(reporter: current_user)
      if @report.save
        # ...
      else
        # ...
      end
    end
    
    private
    
    def report_params
      params.require(:report).permit(:reportable_type, :reportable_id, :content, :radio_content)
    end
    
    <%= form_for @report do |f| %>
      <%= f.hidden_field :reportable_type %>
      <%= f.hidden_field :reportable_id %>
    <% end %>
    
  • [求助] Rails 5.2 多重多态怎么获取正确的 url? at 2018年08月23日
    <%= form_for [@reportable,@report] do |f| %>
    

    这里有错,根据这个参数 form 会推导两级的路由 comment_reports_path,但是路由里并没有这个路由,需要再加上 @question。

    <%= form_for [@question, @reportable, @report] do |f| %>
    

    但是这里可以看到,本来想多态关联 reportable 让 report 跟灵活,却不得不插入不相关的 question,灵活性受阻。

    这里不应该用多级路由,而是一级的 report 路由:

    resources :reports
    

    把 reportable_type 和 reportable_id 作为参数传。

  • Kimurai - 一个 Ruby 写的爬虫框架 at 2018年08月23日

    https://github.com/github/dmca/tree/master/2018

    GitHub DMCA 没有记录,应该是作者自己删的。

  • Kimurai - 一个 Ruby 写的爬虫框架 at 2018年08月23日

    我靠。

  • [求助] Rails 5.2 多重多态怎么获取正确的 url? at 2018年08月23日

    日志贴全。

  • 给 activestorage 顺手撸了个七牛的 service at 2018年08月20日

    彩程那个之前大概半年没更新,也有一些 bug 直接用跑不通,后来提交 issue 之后就更新了。

    代码上我觉得彩程那个功能更专一,assets 我是通过 CDN 回源处理的,不需要扩展 sprokets。

    因为他们前端没用 activestorage.js 而是自己实现,所以 dicret_upload 不能直接用,我想仿照你的实现给他们提个 pr。

    有个问题,你的实现是更改了原先的 xhr 还是另外发起一个,原先的 xhr 会重复发送吗?

  • 给 activestorage 顺手撸了个七牛的 service at 2018年08月20日

    这个 gem 相比 https://github.com/mycolorway/activestorage_qiniu/ 的优势是什么?

  • Ruby 的命名空间提案,引用包时避免污染全局环境 at 2018年08月20日

    是的,我也试试这个方法。

  • NoMethodError (undefined method `User' for #<User:0x00000002586a68>): at 2018年08月20日

    先把这个语法错误改了:

    # wrong
    class User < ApplicationRecord
      has_many :microposts
      validates name, presence: true 
      validates email, presence: true 
    end
    
    # right
    class User < ApplicationRecord
      has_many :microposts
      validates :name, presence: true 
      validates :email, presence: true 
    end
    
  • rails 项目执行 rake db:migrate 时候遇到如下错误,希望大神帮忙看看 at 2018年08月20日

    can't activate mysql2 (< 0.6.0, >= 0.4.4), already activated mysql2-0.3.21

    版本不符合要求,bundle update mysql2 。

  • rails 项目执行 rake db:migrate 时候遇到如下错误,希望大神帮忙看看 at 2018年08月20日

    然后呢?什么错?

  • rails 项目执行 rake db:migrate 时候遇到如下错误,希望大神帮忙看看 at 2018年08月20日

    去掉 activerecord-mysql2-adapter 了没。

  • rails 项目执行 rake db:migrate 时候遇到如下错误,希望大神帮忙看看 at 2018年08月19日

    用这个 gem activerecord-mysql2-adapter 做啥?

    https://github.com/kronn/activerecord-mysql2-adapter

    6 年没更新了,看来只是 ActiveRecord 没支持 mysql2 之前的过度 gem,应该会产生冲突。

  • Ruby 的命名空间提案,引用包时避免污染全局环境 at 2018年08月19日

    我对这个特性不太感兴趣,一来自己的项目通过命名规范隔离已经足够,二来避免使用污染全局空间的库。ActiveSupport 是个特例,它是 Rails 的依赖不得不用,用起来也感觉良好。Rails 不用每个文件写一堆 import 也是它的优点。

    最近用 ActiveStorage 的时候处理 js 端时发现问题,七牛的 js 上传逻辑跟 activestorage.js 里的不一样需要改写,但是这个包经过 ES6 的规范化打包之后,外部完全动不了里面的逻辑。本来只是改写一个方法可以搞定了,结果不得不把整个 js dump 到项目里改写。我还没想好怎么提 pr 让 activestorage.js 提供接口定制不同 service 的上传逻辑。

    所以有了包的概念以后又不得不考虑怎么方便的问题了。

  • Kimurai - 一个 Ruby 写的爬虫框架 at 2018年08月18日

    艹

  • 使用 Protocol Buffers 在 TCP 中需要自己设计协议头以解决 “粘包” 问题吗? at 2018年08月17日

    用 Protocol Buffer 就上 gRPC https://grpc.io/

  • 爬 ruby-china,为什么浏览器看到的和爬到的不一样? at 2018年08月15日

    是不是个人屏蔽了一些用户。

  • 关于 RVM 我有几个问题一直搞不明白...... at 2018年08月14日

    别管 Gemset,被 Bundler 替代了。

  • Kimurai - 一个 Ruby 写的爬虫框架 at 2018年08月13日

    为什么就没人封装一个 jquery 选择器语法的

    前面只是说选择器语法。

  • 10.13-14 郑州见 at 2018年08月13日

    Ruby China 组织会议从来不以营利为目的。

  • 10.13-14 郑州见 at 2018年08月13日

    我找 @jasl 了解了一下,他提供了一些过往的资料,但没有参与组织。其它 Ruby China 的管理员都不知道这件事。

    我觉得 Ruby 社区比较小,要举办 Conf 应该集合社区力量办好一个。今年 jasl 工作繁忙没空组织,已经把会议推倒明年了。如果 @rocLv 想接过大旗,应该跟我们商量(只跟 jasl 讲了),如果合适,由楼主主办,Ruby China 协办,甚至做得好以后就由楼主主办。管理群的人有过往的组织经验、讲师联系方式、赞助商渠道、物料渠道、志愿者关系、录像技术……大伙一起把会议搞好,让 matz 看到中文社区的活力。

    没有规定说 RubyConf China 一定要谁来主办,楼主能邀请到 matz 也是有本事,我现在很担心会议水准不能让 matz 满意。管理群除了 jasl 外都不知道这事,都没有做准备,现在时间也很仓促。

  • 10.13-14 郑州见 at 2018年08月13日

    ??? @jasl

  • Kimurai - 一个 Ruby 写的爬虫框架 at 2018年08月12日

    xpath 可以做到一些 css 做不到的事,例如匹配 Text Node。

  • 翻译一个 jekyll 主题的使用 at 2018年08月12日

    看得不明所以:

    1. 原文是什么?
    2. 主题是什么?
  • [求助] Rails 5.2 使用 carrierwave 上传图片,怎么在选择完图片后,自动上传? at 2018年08月12日

    又看了一次问题,似乎要的只是

    我现在想要的是能不能在使用 carrierwave 选择图片后,后台自动上传到服务器?

    如果只是这样的话,那么只要把表单改成 remote,在 file input 触发 change 事件的时候提交表单就行:

    <%= form_for(@img,:html => {:multipart => true, id: 'img-form'}, :remote => true) do |f| %>
      <%= f.text_field :img_name %>
      <%= file_field_tag :attachment, id: 'attachment-input' %>
      <%= f.submit "upload" %>
    <% end %>
    <script>
      $('#attachment-input').on('change', function() {
        Rails.fire(document.querySelector('#img-form'), 'submit'); // 必须用 Rails.fire,原生的 submit 方法不会触发 rails ujs remote form。
      });
    </script>
    

    至于你想简化表单的参数,那么应该重新考虑模型建立,Img 模型的作用是什么?如果 Img 模型没必要,那么直接创建 Attachment 就好了。

    PS:Attachment 模型多态关联也是有它的用处,Rails 的 ActiveStorage 有 Attachment - Blob 完整的实现,如果需要这种模型可以直接用 ActiveStorage。

  • [求助] Rails 5.2 使用 carrierwave 上传图片,怎么在选择完图片后,自动上传? at 2018年08月12日

    自动上传需要自己写 javascript,原生接口的例子可以看这里:

    https://developer.mozilla.org/en-US/docs/Web/API/File/Using_files_from_web_applications

    我有个示例项目用了 Stimulus 和 Rails.ajax 的例子可以看这里:

    https://github.com/getcampo/campo/blob/7d3574fcb8bf7d4c1fa63fd20f25ec4a9b714243/app/assets/javascripts/controllers/editor_controller.coffee#L4-L20

  • 请问 ruby 标准库中有 ordered hash 这种容器吗 at 2018年08月12日

    啊哈,我理解你意思了,你想要 key 按顺序排列,Ruby Hash 是按插入序。

    迭代的时候手工排序可以吗?

    hash.sort.to_h.each do |key, value|
      # ...
    end
    
  • 请问 ruby 标准库中有 ordered hash 这种容器吗 at 2018年08月12日

    看起来 ActiveSupport::OrderedHash 就是 Hash 而已。

    https://github.com/rails/rails/blob/c3e17bbad88326bd0cb1fcd775c2b2a2929ce59e/activesupport/lib/active_support/ordered_hash.rb

  • 请问 ruby 标准库中有 ordered hash 这种容器吗 at 2018年08月12日

    测试方法是怎么样的?

  • 请问 ruby 标准库中有 ordered hash 这种容器吗 at 2018年08月12日

    好像 1.9 开始默认就是 ordered。

    https://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/

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