Ruby China
  • 社区
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • 注册
  • 登录
Novtopro He
@novtopro
会员
第 15815 位会员 / 2014-11-07

长沙
4 篇帖子 / 126 条回帖
7 关注者
4 正在关注
5 收藏
When the problem is complexity, the cure might just be simplicity.
GitHub Public Repos
  • doc_translator 0

  • webmock 0

    Library for stubbing and setting expectations on HTTP requests in Ruby.

  • pupilfirst 0

    A learning management system (LMS) that lets you run an asynchronous online school, where learnin...

  • niso-jats 0

    Ruby library to work with NISO JATS files

  • oasis-etm 0

    Ruby library for OASIS Exchange Table Model (a subset of CALS table)

  • xml-c14n 0

    Ruby library to canonicalize XML (e.g. for comparison)

  • lutaml-model 0

    LutaML Model is the Ruby data modeler part of the LutaML data modeling suite. It supports creatin...

  • ali 0

    Ruby library for NISO ALI

  • pg_search 0

    pg_search builds ActiveRecord named scopes that take advantage of PostgreSQL’s full text search

  • pev2 0

    Postgres Explain Visualizer 2

More on GitHub
  • 概况
  • 话题
  • 回帖
  • 收藏
  • 正在关注
  • 关注者
  • [杭州] theplant.jp 招聘前端 2 名 (10~30K) at 2017年01月04日

    Vanilla JS is a fast, lightweight, cross-platform framework for building incredible, powerful JavaScript applications. 😄

    https://github.com/Haeresis/vanilla-js-dom

  • 如果有朝一日,Ruby 成为了排名第一的主流语言,你会选择什么职位? at 2016年12月21日

    You're boring enough.

  • API 项目里,如果请求的参数个数较多,需要验证的类型也比较复杂且各个请求之间差异也比较大,在 server 里用什么架构去验证比较好? at 2016年12月14日

    如果只要求简单的校验清洗,我觉得就没有必要搞那么复杂。

  • API 项目里,如果请求的参数个数较多,需要验证的类型也比较复杂且各个请求之间差异也比较大,在 server 里用什么架构去验证比较好? at 2016年12月14日
    1. 需要单独的文件
    2. 文件名按照约定来,Rails 强调的不也是 Convention over Configuration 嘛
    3. 当然需要维护,也不算大。

    因为我目前也是按照 JSON API 规范去构建 API,我 Explore 了一下其它的参数校验清洗 gem,包括 strong_parameters, rails_param 感觉都不是很满意,hanami-validation 和 dry-validation 的逻辑表达能力实在太好了,于是就用了。

    其实我也不知道这种方式好不好,不过就目前来看也还 OK

  • API 项目里,如果请求的参数个数较多,需要验证的类型也比较复杂且各个请求之间差异也比较大,在 server 里用什么架构去验证比较好? at 2016年12月14日

    @realwol

    ApplicationController

    class Api::BaseController < ActionController::API
      before_action :sanitize
    
      helper_method :sanitized_params
    
      private
    
      def sanitized_params
        @sanitized_params ||= begin
          sanitizer ? sanitization.output : request.parameters
        end
      end
    
      def sanitize
        render_errors(sanitization.messages, :bad_request) && return if sanitization && sanitization.failure?
      end
    
      def sanitization
        @sanitization ||= sanitizer ? sanitizer.call(request.parameters.to_h) : nil
      end
    
      def sanitizer
        @sanitizer ||= begin
          controller_without_suffix = request.controller_class.to_s.match(/^(.*)Controller$/)[1]
          action                    = params[:action].titleize
          "#{controller_without_suffix}::#{action}Validation".safe_constantize
        end
      end
    end
    

    A simple sanitizer: Posts::IndexValidation

    class Api::V1::Posts::IndexValidation < Api::V1::Validation
      validations do
        optional(:sort).filled
        optional(:filter).filled
        optional(:page).schema do
          optional(:number).filled
          optional(:size).filled
        end
      end
    end
    

    PostsController

    class Api::V1::PostsController < Api::BaseController
      def index
        # Use sanitized_params here
      end
    end
    
  • API 项目里,如果请求的参数个数较多,需要验证的类型也比较复杂且各个请求之间差异也比较大,在 server 里用什么架构去验证比较好? at 2016年12月14日

    很多人批评 hanami 将一个 action 独立成一个类的方式,但这其实赋予了 action 更大的灵活性。使用 rails_param,你的 action 很快就会充满各种参数过滤清洗逻辑,当然,你可以对其进行抽取分离,但是效果也并不是很好。反观 hanami-validation,一方面参数过滤清晰表达能力更强,另一方面能够跟 action 的逻辑进行有效分离。

    推荐 hanami-validation 或者 dry-validation (其实他们是一伙的),至于怎样整合进入 Rails,我目前是在 application_controller 里面加入一个 before_action, 根据对应的 controller+action 按照某种约定查找对应的 validation,暴露一个 sanitized_params helper 方法给后续的 action 逻辑

  • [厦门] 诚聘 Python、Ruby 高级开发工程师 (月薪 15k-25k) at 2016年12月02日

    好厉害

  • 如何处理数组的 strong params? at 2016年12月02日

    strong_params 还是弱了一点,hanami-validation 或者 dry-validation 对于参数的 sanitize 和验证更强。

  • 如何处理数组的 strong params? at 2016年12月02日

    params.require(:product).permit(:name, tags: [])

  • Rails 开发互动媒体学习社区--毕业设计新人请教了 at 2016年12月01日

    开一个 repo,不是 pro

  • [译] 重构 Rails MVC 组件的 7 个设计模式 at 2016年12月01日

    #6 楼 @kikyous 也没有炫技吧,逻辑/UI 复杂度到一定程度选择使用就好了,简单的没有必要。

  • API 需要专门的框架吗?不是所有框架都能做 API 吗 at 2016年11月28日

    可以问问希拉里

  • 如何安装 phantomjs 2.0.0 版本 ?求助 at 2016年11月22日

    I think it's clear enough. Just follow the error messages and you'll find your way.

  • 如何安装 phantomjs 2.0.0 版本 ?求助 at 2016年11月22日

  • UPYUN 支持 Elixir hex.pm 国内镜像 at 2016年11月18日

    🎉

  • Docker 安装 homeland at 2016年11月16日

    Client: 1.21

    Engine: 1.18

  • Docker 安装 homeland at 2016年11月16日

    你的 Docker Client 跟 Docker Engine 的版本不一致

  • Ruby 2.3.2 Released at 2016年11月16日

    🎉

  • 我收到上家给我发的律师函了,该怎么办? at 2016年11月16日

    You're boring enough.

  • RubyConf China 2016 视频 at 2016年11月03日

    #35 楼 @vincent Sounds like simple_command

  • 建议支持帖子和节点多对多 (一个可以放入多个节点下) at 2016年10月31日

    Sounds like tag, not node / category

  • [佛山] 楼兰电商诚聘 Ruby 工程师 8 名 (10K ~ 25K) at 2016年10月24日

    👍

  • [广州] 广州又一客 ( 加拿大电商 Shopper+ ) 招聘 2 -4 位 Ruby / Rails 工程师 ( 5K - 15K ) at 2016年10月24日

    支持雨哥

  • 有没有啥办法让 Ruby 发生异常的时候打印 log 是倒序的 at 2016年10月20日

    #5 楼 @greatghoul You get it. Sentry is awesome.

  • 不写测试代码 at 2016年10月20日

    Test Driven Design. 当你发现你很难给一个功能添加测试的时候,很可能你没有好的 OO Design。另外可靠的测试也是很重要,所以"Write a test for your test" 🐮

  • 有没有啥办法让 Ruby 发生异常的时候打印 log 是倒序的 at 2016年10月19日

    #3 楼 @guyanbiao *nix pipe

  • CarrierWave 如何从云存储下载文件。 at 2016年08月12日

    #7 楼 @huacnlee 好有耐心

  • 如何获取 post 中的 jsonapi 参数 at 2016年08月10日

    params.dig(:data, :attributes, :name)

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