Ruby China
  • Topics
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • Sign Up
  • Sign In
刘二狗
@coderliu
Member
NO. 23873 / 2015-12-07

[email protected]
厦门
2 Topics / 130 Replies
7 Followers
29 Following
62 Favorites
GitHub Public Repos
More on GitHub
  • Overview
  • Topics
  • Replies
  • Favorites
  • Following
  • Followers
  • ActiveAdmin 定制化实战 at July 14, 2020

    感谢分享,都是一些很实用的技巧,已经接近两年没用 ActiveAdmin 了,翻了翻自己的陈年老代码,我也分享一些个人感觉有些作用的技巧吧😂

    • 指定某些 controller 下引入特定的 JS 文件。当时应该是为了只在需要用到富文本编辑器的页面去引用对应的 JS。
    # config/initializers/active_admin.rb
    module AdminPageLayoutOverride
      def build_active_admin_head
        # you can move the call to super at the end, if you wish
        # to insert things at the begining of the page
        super
    
        # this will be added at the end of <head>
        within @head do
          white_list = %w(admin/announcements admin/distributions admin/introductions admin/versions)
          if params['controller'].in?(white_list)
            text_node javascript_include_tag(params['controller'])
          end
        end
      end
    end
    ActiveAdmin::Views::Pages::Base.send :prepend, AdminPageLayoutOverride
    
    • 增加自定义的 attribute
    # config/initializers/active_admin.rb
    module ActiveAdmin
      module Views
        class RtfContent < ActiveAdmin::Component
          builder_method :rtf_content
    
          def build(content, attributes = {})
            super(attributes)
            textarea class: 'rtf-content-ckeditor', name: SecureRandom.uuid do
              content
            end
          end
        end
      end
    end
    
    • 在多个 namespace 使用 ActiveAdmin + Devise
    # config/initializers/active_admin.rb
    ActiveAdmin.setup do |config|
    #...
      config.namespace :admin do |ns|
        ns.site_title = "Admin System"
        ns.authentication_method = :authenticate_admin_user!
        ns.authorization_adapter = ActiveAdmin::PunditAdapter
        ns.pundit_default_policy = 'AdminPolicy'
        ns.current_user_method = :current_admin_user
        ns.logout_link_path = :destroy_admin_user_session_path
      end
    
      config.namespace :public do |ns|
        ns.site_title = "Public NS"
        ns.site_title_link = '/public'
        ns.authentication_method = :authenticate_teacher!
        ns.current_user_method = :current_teacher
        ns.logout_link_path = :destroy_teacher_session_path
        ns.footer = '教师工作台'
      end
    #...
    end
    
    # Devise 的处理
    class ActiveAdmin::Devise::SessionsController
      def after_sign_out_path_for(resource_or_scope)
        case resource_or_scope
        when :teacher
          new_teacher_session_path
        when :admin_user
          new_admin_user_session_path
        end
      end
    
      def after_sign_in_path_for(resource)
        case resource
        when Teacher
          public_root_path
        when AdminUser
          admin_dashboard_path
        end
      end
    end
    
  • 2.7 开始,私有方法 getter 可以显示指定 self 接收者(会和很多书上的描述打架),getter,setter 保持一致 at June 24, 2020

    反过来想一想:如果 private 方法在 class 内部都不能调用,那什么时候允许调用?

  • 如何为当前 URL append 参数? at June 23, 2020

    维护一个允许的参数白名单,但是新增参数的时候一不小心就会忘记掉,导致生成 URL 的时候参数丢失

  • 发现一个 bug at June 20, 2020

    😂 我这个“新手”终于又能回帖了

  • jbuilder 使用多层 partial! 需谨慎,渲染有可能很慢 at June 08, 2020

    之前在生产环境一个小 partial 用时是 0.1 ms,但是因为要调用 1000 次,算下里也要用 100ms,果断去掉了。楼主的 100 ms 是本地开发环境还是生产环境的数据? 如果是本地的,建议测一下 production 的情况。如果是 production 的,那多半不是 partial 的锅。

  • Shadow Table for Postgres at January 10, 2020

    https://github.com/jhawthorn/discard#why-not-paranoia-or-acts_as_paranoid

    跑个题,软删除的需求最好选择 discard,paranoia 侵入性太强了

  • Rails 项目多机部署后,job 中生成文件代码造成的困惑 at January 06, 2020

    因为你两台服务器都是 sidekiq 的 consumer,job 可能被被分配到任意一台执行

  • 如何显示关联查询的全部内容 at September 28, 2019

    Agency.includes(:project).where("project.score > 60")

  • 对象某个字段用了 enumerize 这个 gem,attributes 方法获取的值被改写了,有什么解决办法吗? at September 25, 2019

    这个就是 gem 的 feature 吧

    获取原始值可以试试 user.type_id_before_type_cast

  • GitHub 宣布已经顺利升级到 Rails 6.0 at September 12, 2019

    Running GitHub on Rails 6.0

  • [绍兴柯桥 / 杭州萧山] 有数派 诚聘 Ruby 后端、React、React Native 前端工程师 / 长期有效 ( 15K - 30K ) at August 29, 2019

    RubyConf China 2019 最大赢家 —— 有钱派😂 👏

  • Ruby Conf China 2019 你最喜欢的主题投票 [Hot 5 已更] at August 26, 2019

    好像没看到 @ericguo 分享的主题?


    这个: 从 Assets Pipeline 到 Webpack,Rails 6 的新前端方案们

  • RubyConf China 2019 录像 [更新完毕] at August 26, 2019

    录制及转压幸苦了👍

  • Black candy - 基于 Rails 构建的个人音乐流媒体应用 at July 01, 2019

    👍

  • Enumize - 扩展 ActiveRecord::Enum 增加实用方法 at June 24, 2019

    很实用,以前都是手动调用 i18n 👍

  • [上海][8-24,25] RubyConf China 2019 售票开始 at June 20, 2019

    性感姜军,在线卖票,不买即亏

  • [上海][8-24,25] RubyConf China X 讲师和主题介绍 at June 20, 2019

    期待👏

  • Rails API 项目的后台 怎样写会比较好呢 at May 12, 2019

    https://medium.com/alturasoluciones/how-to-set-up-rails-api-app-to-use-activeadmin-79b418df8aad

    https://blog.heroku.com/a-rock-solid-modern-web-stack

    放一个项目里没什么问题,就算你原来是个 api mode 的项目,也可以往里加 activeadmin

  • [北京] [2019年3月9日] Ruby Saturday「结束,包含 Keynotes」 at March 12, 2019

    keynote 链接都是错的

  • 关于腾讯 API 拼 URL 的服务 at December 15, 2018
    RestClient::Request.execute(method: :get, url: 'http://example.com/resource',
                                timeout: 10, headers: {params: {foo: 'bar'}})
    # ➔ GET http://example.com/resource?foo=bar
    

    当年也是因为要用腾讯的 API 才知道 RestClient 还可以这么用的

  • It's never too late to learn Postgres at November 24, 2018

    炮神可以分享一下你的 PG 学习路线吗?

  • [深圳] 中原地产 诚邀 Ruby 软件工程师~ at November 22, 2018

    不如从门店拉几个中介从 0 入门吧

  • Ruby China 的最后回覆里有个 bug at November 19, 2018

    应该是机器人被屏蔽了

  • [远程] FeedMob 诚招 Ruby Developer 和 DBA (已招满) at November 15, 2018

    简历已发邮箱,期待回复😬

  • 如何给 Rails 做 health check at November 10, 2018

    /health 会 timeout,说明此时该服务器的负载确实已经太高了。要么你的 timeout 太小了,要么就是触发创建新 container 条件不够“敏感”

  • Rails job 默认的 Active Job 如何不并发调同一方法 顺序执行方法 at November 09, 2018

    生产环境使用 Sidekiq 的话可以创建一个长度为 1 的队列专门用来跑这类任务,这样不会影响到并行的其它任务。有这种需求直接在开发环境就用 Sidekiq 吧

  • 如何给 Rails 做 health check at November 09, 2018

    这种情况应该更改的是监控的指标吧?比如说 x 分钟内 CPU、内存占用率之类的,通过这种指标来触发创建 container。health check 和 load monitoring 应该分开

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