Skip to content

Instantly share code, notes, and snippets.

<nav class="navbar-nav navbar-default">
<% if user_signed_in? %>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<span class="glyphicon glyphicon-globe"></span>
</a>
<ul class="dropdown-menu" role="menu">
<% if @messages.any? %>
<% @messages.each do |msg| %>
<li class="drop-links"> <%= link_to 'you received a message from ' + User.find(msg.sender_id).username, conversation_path(msg.conversation_id), remote: true %></li>
def bakery_num(num_of_people, fav_food)
#Release 2 - Initializing the hash and the variables of the amount of food.
my_list = {"pie" => 8, "cake" => 6, "cookie" => 1}
pie_qty = 0
cake_qty = 0
cookie_qty = 0
has_fave = false
# Release 3
##routes.rb
Rails.application.routes.draw do
resources :authentications
root to: "static_pages#home"
get 'static_pages/books'
devise_for :users, controllers: {omniauth_callbacks: "authentications", registrations: "registrations"}
end
@tgoldenberg
tgoldenberg / gist:39f7694b6afe886a054d
Created April 27, 2015 03:30
How to get FB profile photo in devise new user form
## routes.rb
Rails.application.routes.draw do
devise_for :users, controllers: {registrations: 'registrations', omniauth_callbacks: 'omniauth_callbacks'}
root 'pages#home'
end
##config/initalizers/devise.rb
config.omniauth :facebook, 'your-app-key', "your-secret-key", :image_size => 'large'
### requests/new.html.haml
= simple_form_for @request, remote: true do |f|
- if @request.errors.any?
#error_explanation
%h2= "#{pluralize(@request.errors.count, "error")} prohibited this request from being saved:"
%ul
- @request.errors.full_messages.each do |msg|
%li= msg
= simple_form_for @charge, remote: true do |f|
= f.hidden_field :price, value: @request.recipient.price
= f.hidden_field :description, value: @request.recipient.name
= f.hidden_field :owner_id, value: @request.recipient.id
= f.hidden_field :vendor_id, value: params[:recipient_id]
= f.submit 'Send', id: 'charge-submit'
%script{src:"https://checkout.stripe.com/checkout.js", class:"stripe-button", data: {key: ENV["stripe_publishable_key"], price:"#{@request.recipient.price*100}", name:"ChessMentor", vendor_id: "#{@request.recipient.id}", description: "#{number_to_currency(@request.recipient.price)}", image: "/assets/landing_background.png"}}
@tgoldenberg
tgoldenberg / gist:d0fd0eb2acaa090e0f28
Last active August 29, 2015 14:22
HTTP request class
class HttpRequest
attr_reader :method, :request_uri, :http_version
def initialize(website_string)
@method = website_string.split.first.upcase
@request_uri = website_string.split[1]
@http_version = website_string.split[2]
end
def to_hash
{method: @method, request_uri: @request_uri, http_version: @http_version}
<div class="container">
<div class="well">
<h2 style="font-weight: 200;">You are playing the following deck: <b> <%= @game.deck.name %></b></h2>
<div class="score-holder" style="display: flex;">
<p class="score-counter">Correct answers: <%= @game.right %></p>
<p class="score-counter">Incorrect answers: <%= @game.wrong %></p>
</div>
</div>
<hr />
<div class="row">
@tgoldenberg
tgoldenberg / gist:040b42f70f0fac68a364
Last active August 29, 2015 14:23
First-level ReactJS abstraction
##games/show.html.erb
<%= react_component("App", @data %>
## games_controller.rb
def show
@game = Game.current_game_by_id(params[:id])
@user = User.find(session[:user_id])
@card = @game.deck.cards[@game.card_idx]
@tgoldenberg
tgoldenberg / ReactJS-example-2
Last active September 15, 2016 09:03
Main files for ReactJS components
## assets/javascripts/components/App.jsx
var App = React.createClass({
getInitialState: function() {
return { data: this.props, messages: [] };
},
handleNewAnswer: function(data) {
var newData = this.state.data;