ModelUpdates
Rails gem to push updates to models into the frontend through ActionCable.
Installation
Add this line to your application's Gemfile:
gem 'model_updates'
And then execute:
$ bundle
Or install it yourself as:
$ gem install model_updates
Usage
Include it in your JavaScript:
//= require model_updates
Include the helper in your models:
class ApplicationRecord < ActiveRecord::Base
include ModelUpdates::ModelExtensions
end
Choose which attributes should be broadcasted automatically:
class Model < ApplicationRecord
model_updates_broadcast_attributes attributes: [:updated_at]
end
Do like this in your views if you are using HAML:
.model-updates{data: {model_updates: model.model_updates_data_attrs(:updated_at)}}
= model.updated_at
Or like this in ERB:
<div class="model-updates" data-model-updates-model="Model" data-model-updates-id="1" data-model-updates-key="updated_at">
<%= model.updated_at %>
</div>
Now that element should update automatically when the model is changed
Contributing
Contribution directions go here.
License
The gem is available as open source under the terms of the MIT License.