Skip to content

Instantly share code, notes, and snippets.

View superhighfives's full-sized avatar

Charlie Gleason superhighfives

View GitHub Profile
@superhighfives
superhighfives / ingredients_controller.rb
Last active March 4, 2017 13:10
Rails 5 API + ActiveAdmin + create-react-app on Heroku
class IngredientsController < ApiController
end
@superhighfives
superhighfives / drinks_controller.rb
Last active March 4, 2017 13:10
Rails 5 API + ActiveAdmin + create-react-app on Heroku
class DrinksController < ApiController
# GET /drinks
def index
@drinks = Drink.select("id, title").all
render json: @drinks.to_json
end
# GET /drinks/:id
def show
@drink = Drink.find(params[:id])
@superhighfives
superhighfives / ingredient.rb
Last active March 6, 2017 17:08
Rails 5 API + ActiveAdmin + create-react-app on Heroku
ActiveAdmin.register Ingredient do
permit_params :description, :drink_id
# See permitted parameters documentation:
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
#
# permit_params :list, :of, :attributes, :on, :model
#
# or
#
@superhighfives
superhighfives / drink.rb
Created March 3, 2017 00:28
Rails 5 API + ActiveAdmin + create-react-app on Heroku
ActiveAdmin.register Drink do
permit_params :title, :description, :steps, :source
# See permitted parameters documentation:
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
#
# permit_params :list, :of, :attributes, :on, :model
#
# or
#
@superhighfives
superhighfives / seeds.rb
Created March 3, 2017 00:14
Rails 5 API + ActiveAdmin + create-react-app on Heroku
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Character.create(name: 'Luke', movie: movies.first)
AdminUser.create!(email: 'admin@example.com', password: 'password', password_confirmation: 'password')
negroni = Drink.create(
@superhighfives
superhighfives / drink.rb
Created March 2, 2017 23:58
Rails 5 API + ActiveAdmin + create-react-app on Heroku
class Drink < ApplicationRecord
has_many :ingredients
end
@superhighfives
superhighfives / application.rb
Last active March 2, 2017 23:57
Rails 5 API + ActiveAdmin + create-react-app on Heroku
require_relative 'boot'
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
@superhighfives
superhighfives / error
Created March 2, 2017 18:40
Rails 5 API + ActiveAdmin + create-react-app on Heroku
$ bin/rails g scaffold drink
Running via Spring preloader in process 38277
Expected string default value for '--serializer'; got true (boolean)
invoke active_record
create db/migrate/20170302183027_create_drinks.rb
create app/models/drink.rb
invoke test_unit
create test/models/drink_test.rb
create test/fixtures/drinks.yml
invoke resource_route
@superhighfives
superhighfives / Gemfile
Created March 2, 2017 18:01
Rails 5 API + ActiveAdmin + create-react-app on Heroku
group :development do
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'foreman', '~> 0.82.0'
end
@superhighfives
superhighfives / start.rake
Last active March 4, 2017 14:35
Rails 5 API + ActiveAdmin + create-react-app on Heroku
namespace :start do
task :development do
exec 'foreman start -f Procfile.dev'
end
desc 'Start production server'
task :production do
exec 'NPM_CONFIG_PRODUCTION=true npm run postinstall && foreman start'
end
end