Ruby China
  • Topics
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • Sign Up
  • Sign In
Novtopro He
@novtopro
Member
NO. 15815 / 2014-11-07

长沙
4 Topics / 126 Replies
7 Followers
4 Following
5 Favorites
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
  • Overview
  • Topics
  • Replies
  • Favorites
  • Following
  • Followers
  • [杭州] theplant.jp 招聘前端 2 名 (10~30K) at January 04, 2017

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

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

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

    You're boring enough.

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

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

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

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

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

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

    @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 December 14, 2016

    很多人批评 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 December 02, 2016

    好厉害

  • 如何处理数组的 strong params? at December 02, 2016

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

  • 如何处理数组的 strong params? at December 02, 2016

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

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

    开一个 repo,不是 pro

  • [译] 重构 Rails MVC 组件的 7 个设计模式 at December 01, 2016

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

  • API 需要专门的框架吗?不是所有框架都能做 API 吗 at November 28, 2016

    可以问问希拉里

  • 如何安装 phantomjs 2.0.0 版本 ?求助 at November 22, 2016

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

  • 如何安装 phantomjs 2.0.0 版本 ?求助 at November 22, 2016

  • UPYUN 支持 Elixir hex.pm 国内镜像 at November 18, 2016

    🎉

  • Docker 安装 homeland at November 16, 2016

    Client: 1.21

    Engine: 1.18

  • Docker 安装 homeland at November 16, 2016

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

  • Ruby 2.3.2 Released at November 16, 2016

    🎉

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

    You're boring enough.

  • RubyConf China 2016 视频 at November 03, 2016

    #35 楼 @vincent Sounds like simple_command

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

    Sounds like tag, not node / category

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

    👍

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

    支持雨哥

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

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

  • 不写测试代码 at October 20, 2016

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

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

    #3 楼 @guyanbiao *nix pipe

  • CarrierWave 如何从云存储下载文件。 at August 12, 2016

    #7 楼 @huacnlee 好有耐心

  • 如何获取 post 中的 jsonapi 参数 at August 10, 2016

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

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