This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[obj1, obj2, obj3, ...].group_by{|x| x.created_at.strftime("%Y-%m-%d")} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Price < ApplicationRecord | |
module Scopes | |
def daily | |
created_at.to_date.to_s(:db) | |
end | |
def weekly | |
where('created_at >= ?', 1.week.ago) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.most_recent | |
{ data: { base: 'BTC', currency: 'USD', amount: last.price } } | |
end | |
def self.recent_prices(market_id = 1, coin = 1) | |
search = query_elastic(market_id, coin) | |
return [] unless search.aggregations.present? | |
time_intervals = search.aggregations.dig('five_time_intervals', 'buckets') | |
time_intervals.inject([]) do |interval, i| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_candlestick(group) | |
{ | |
date: group[0], | |
open: opening_price(group[1]), | |
close: closing_price(group[1]), | |
low: lowest_price(group[1]), | |
high: highest_price(group[1]) | |
} | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Comment Form | |
<%= form_for [@post, Comment.new] do |f| %> | |
<%= f.text_field :body, placeholder: "Comment", class: "form-control", required: true, size: "30x10" %> | |
<%= f.submit %> | |
<% end %> | |
# Post Controller | |
def show | |
@post = Post.find(params[:id]) | |
end |
OlderNewer