Skip to content

Instantly share code, notes, and snippets.

View andrewariley87's full-sized avatar

Andrew Riley andrewariley87

  • Tangoe
  • Carmel, IN
View GitHub Profile
require 'pry'
class Fixnum
# number = self
# rn = ""
# ROMAN_KEYS.each do |key, value|
# rn << key if ((value % number == 0) && (value / number == 1))
# end
# if number > 5 && number < 9
# rn << "V"
Started GET "/" for ::1 at 2015-10-11 18:18:48 -0400
Processing by DestinationsController#index as HTML
Destination Load (1.0ms) SELECT "destinations".* FROM "destinations"
Rendered destinations/index.html.erb within layouts/application (41.5ms)
CACHE (0.0ms) SELECT "destinations".* FROM "destinations"
CACHE (0.0ms) SELECT "destinations".* FROM "destinations"
Completed 200 OK in 2220ms (Views: 2206.6ms | ActiveRecord: 1.0ms)
Started GET "/assets/application.self-99f5ac3e89ffcb4d26c90edbce76e53d36b977623e378a757511e1133bca0472.css?body=1" for ::1 at 2015-10-11 18:18:51 -0400
The files belonging to this database system will be owned by user "andrewariley87".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
initdb: directory "/usr/local/var/postgres" exists but is not empty
(1) array = [1,2,3,4,5]
array.inject(0){|sum, num| sum + num}
(2) new_array = []
array.each do |num|
product = num * 3
Andrews-MacBook-Air:Own_Notes andrewariley87$ curl -H "content-type: application/json" --request POST --data '{"title":"My created post", "body":"My created body"}' http://localhost:3000/notes
{"title":"My created post","body":"My created body"}Andrews-MacBook-Air:Own_Note/json" --request POST --data '{"title":"My created post", "body":"My created body"}' http://localhost:3000/notes
{"title":"My created post","body":"My created body","created_at":"2015-08-25T21:17:30.193Z","updated_at":"2015-08-25T21:17:30.
This is as far as I was getting before active model serializer
After I was not able to get things working with serializer, also the olny error message I recieved when not puttint a body or title on the note was a 500 not a 400 error.
curl -H "content-type: application/json" --request POST --data '{"title":"My created post", "body":"My created body","tags":"api, machine, first"}' http://localhost:3000/notes
{"id":7,"title":"My created post","body":"My created body","created_at":"2015-08-26T02:44:01.022Z"
Rails.application.routes.draw do
post 'posts/follow' => 'posts#follow', as: :follow
post 'posts/unfollow' => 'posts#unfollow', as: :unfollow
resources :posts
devise_for :users, controllers: {registrations: "registrations"}
resources :after_signup
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
def follow
@post = Post.find(params[:id])
if @post.user_id == current_user.id
flash[:error] = "You can't follow yourself"
redirect_to(posts_path)
else
current_user.follow(@post.user)
flash[:notice] = "You are now following #{@post.user.name}."
redirect_to(posts_path)
end
class ProfileController < ApplicationController
before_action :set_post
def follow
if current_user.id == @post.user_id
flash[:error] = "You can't follow yourself"
redirect_to(posts_path)
else
current_user.follow(@post.user)
flash[:notice] = "You are now following #{@post.user.name}."
require 'test_helper'
class AuthorTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
test "an author should have posts"
post = Post.create(:title => "a", :body => "b", :summary => "c")
author = Author.create(:name => "zzz")
Last login: Mon Jul 27 13:20:27 on ttys002
Andrews-MacBook-Air:~ andrewariley87$ sqlite3 classroom.sqlite3
SQLite version 3.8.5 2014-08-15 22:37:57
Enter ".help" for usage hints.
sqlite> CREATE TABLE students (id INTEGER, first_name TEXT, last_name TEXT); Error: table students already exists
sqlite> INSERT INTO students(id, first_name, last_name) VALUES(1, "Alec", "Martin");
sqlite> INSERT INTO students(id, first_name, last_name) VALUES(2, "Andrew", "Riley");
sqlite> INSERT INTO students(id, first_name, last_name) VALUES(3, "Caleb", "Francis");
sqlite> INSERT INTO students(id, first_name, last_name) VALUES(4, "Dallie", "Hill");
sqlite> INSERT INTO students(id, first_name, last_name) VALUES(5, "Daniel", "Beyrer");