Skip to content

Instantly share code, notes, and snippets.

@farmanp
farmanp / comment.rb
Created December 29, 2016 20:58
Posts relationships
class Comment
include Neo4j::ActiveNode
property :name, type: String
property :content, type: String
has_one :out, :post, type: :post
has_one :in, :post, rel_class: :AgreeComment
has_one :in, :post, rel_class: :DisagreeComment
end
@farmanp
farmanp / _form.html.erb
Created December 29, 2016 19:46
Undefined properties from and to
<%= form_for([@post, @comment]) do |f| %>
<% if @comment.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:</h2>
<ul>
<% @comment.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
@farmanp
farmanp / bill_controller.rb
Last active November 20, 2016 18:38
Secrets
class BillsController < ApplicationController
LEGISCAN_URL = 'https://api.legiscan.com/?key='
LEGISCAN_STATE_SEARCH = 'op=getMasterList&state='
LEGISCAN_STATE_API_CALL = LEGISCAN_URL + LEGISCAN_API_KEY + LEGISCAN_STATE_SEARCH
def show
//ERROR RETUNS NIL ON IMPLICIT STRING CONVERSION FOR API KEY ABOVE
@bill_api = JSON.parse(HTTParty.get('https://api.legiscan.com/?key=77f939393jfjfdcb&op=getBill&id=' + params[:id]).body)
end
@farmanp
farmanp / example.js
Last active July 24, 2016 21:18
Create a variable outside the global scope
// Create a function that holds another function which will "create" a name
function init(){
// Global variable inside the function to be used after initialization
firstName = "FIRST NAME"
// Second function is what returns the global variable
function createName(n){
return n
}
return createName(firstName);
}