百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
G

get_schwifty

> 编程语言
开源

在后台作业队列中渲染 Rails 视图的部分内容。ActiveJob + ActionCable。

186 stars0 点赞4 次浏览
访问官网GitHub

工具介绍

在后台作业队列中渲染 Rails 视图的部分内容。ActiveJob + ActionCable。

get_schwifty

Oh, yeah! You gotta get schwifty. You gotta get schwifty in here.

get_schwifty is a Rails plugin for rendering slow view partials in a background job and sending them to the client over ActionCable websockets.

Justification

Slow-to-render HTML elements can be expensive (hosting) and unavoidable (technical debt, slow libs, expensive db queries, etc). Rendering in-line in your web server consumes a connection which could be serving other clients. Sometimes it's better to just return a minimal page quickly, and let the data backfill as it's generated.

get_schwifty is all about quick responses by utilizing background jobs to do the rendering for your and delivering it to the client with ActionCable.

Caveats

  • There is no gurantee that the content will load. If your background job queue get's backed up, you'll be not showing content anytime soon.

Extracted from HireLoop

get_schwifty was extracted from HireLoop.io, a platform for a more human hiring experience.

Make hiring delightful by closing the loop between hiring managers and every applicant. Automate the trival tasks associated with screening job applicants, lowering the barrier for easy and clear communication.

Installation

Add this line to your application's Gemfile:

ruby
gem "get_schwifty"

And then execute:

bash
$ bundle

Or install it yourself as:

bash
$ gem install get_schwifty

Install the plugin

bash
$ rails generate get_schwifty:install

Follow the instructions printed.

Usage

Generate your first get_schwifty Cable

bash
$ rails generate get_schwifty:cable Calculator fibonacci

Cables are a place to put your data access logic. Think Controllers for each get_schwifty cable.

ruby
# app/cables/calculator_cable.rb

class CalculatorCable  is 

Lastly, we need to tell the app where to render this chunk of HTML. get_schwifty uses a similar routing syntax to Rails routes of cablecontrollername#action.

erb
# app/views/yourpage.html.erb
... Other HTML ...

  

    This will get displayed while the cable is waiting to get schwifty.
    Maybe markup for a loading animation?
  

... Other HTML ...

Load the page, and you should get the whole page back quickly, while the Fibonacci comes later.

Identifiers & Params

Random data isn't very useful. Unauthenticated data isn't very cool either. Usually in Rails data scoping belongs starts at a current_user method. get_schwifty will make any identefiers or params made available in the channel subscription within your cables. Let's take a look at an example.

Identifiers

Here we'll find the current user. This is copied form the Rails Guides.

ruby
# app/channels/connection.rb
module ApplicationCable
  class Connection 
  ... same as before ...

... Other HTML ...

These params will be available in your cable action.

ruby
# app/cables/calculator_cable.rb

class CalculatorCable < BaseCable
  def fibonacci
    n = SecureRandom.rand(params[:min_start]..40)
    ... same code as before ..
  end
end

License

The gem is available as open source under the terms of the MIT License.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言