
Ruby on Rails
12
Вклад в тег
class MessagesChannel < ApplicationCable::Channel
def subscribed
stream_from "messages"
end
end
(function() {
this.App || (this.App = {});
App.cable = ActionCable.createConsumer('/cable');
}).call(this);
ActionCable.server.broadcast('messages', message.to_json)
App.messages = App.cable.subscriptions.create('MessagesChannel', {
received: function(data) {
var jsonObj = JSON.parse(data);
....
class User < ApplicationRecord
validates_with UserBirthZalupaValidator
end
class UserBirthZalupaValidator < ActiveModel::Validator
def validate(record)
begin
birth = Date.parse(record.birth_date.to_s)
record.errors.add(:base, "zlpa") unless birth.between?(start_date, end_date)
rescue StandardError => e
Rails.logger.error("Full zlpa: #{e.inspect}")
end
end
def start_date
Date.new(1900,1,1)
end
def end_date
Time.zone.today
end
end