Skip to content

Instantly share code, notes, and snippets.

View PrimeTimeTran's full-sized avatar
🎯
Focusing

Loi Tran PrimeTimeTran

🎯
Focusing
View GitHub Profile
# frozen_string_literal: true
class Price < ApplicationRecord
module Scopes
def daily
created_at.to_date.to_s(:db)
end
def weekly
where('created_at >= ?', 1.week.ago)
class Price < ApplicationRecord
module Scopes
def daily
created_at.to_date.to_s(:db)
end
def weekly
where('created_at >= ?', 1.week.ago)
end
def five_minute_prices
time = Time.zone.now.end_of_day
first_price = Price.first.created_at
prices = {}
while first_price < time
earlier_time = time - 300
later_time = time
prices[time] = []
r = Range.new(earlier_time, later_time)
[obj1, obj2, obj3, ...].group_by{|x| x.created_at.strftime("%Y-%m-%d")}
// PURPOSE:
// to prevent green dot from going grey on simple user navigations to different parts of the app
// PROBLEM:
// if the user 'x's the tab of their browser, this ActionCable method never runs, thus the user is always online
disconnected: function() {
setTimeout(function () {
if (!App.cable) {
this.perform("disappear");
}
def create
@comment = current_user.comments.create!(comment_params)
@parent = params[:comment][:parent_id]
PostMailer.commented_post(@comment.post.user_id, current_user).deliver_now unless Post.mine?(@comment.post.id, current_user)
Rb::PhotoUploadService.upload(current_user.id, self.class, @comment.id, params[:comment][:photo]) if params[:comment][:photo]
respond_to do |format|
if @comment.save
format.html { redirect_back(fallback_location: root_path) }
format.js
<%= form_for @ticket do |f| %>
<div class="row">
<div class="col-md-11 col-md-offset-1">
<table class="table">
<th>Ticket Type</th>
<th>Unit Price</th>
<th>Quantity</th>
<% @event.ticket_types.each do |type| %>
<tr>