Skip to content

Instantly share code, notes, and snippets.

@jennli
jennli / rails-react-app.md
Last active July 20, 2020 01:27
rails-react-app

create:

rails new react-js-amazon-app --webpack=react -d=postgresql

or if api only

rails new products_api --api -d=postgresql

Topic

 @user
 Class hello
 

Linux

  • installation
  • apt-get
  • yum

SSH

  • SSH, TCP, IP, Network
  • default port is 22
  • VPS: virtual private server
  • stripe info should never be saved and sent through rails server

  • user fills out the form, send the credit card info to stripe server through ajax

  • stripe server sends a one time token to rails server

  • generate a migration

class AddStripeFieldsToDb < ActiveRecord::Migration
  def change
    add_column :pledges, :stripe_txn_id, :string

Decorator

  • object that inherits from that object that adds more functions, method, etc, to it
gem 'draper', '~> 1.3'
  • generates the decorator for Campaign
bin/rails g decorator Campaign
  • generate commentable
bin/rails g model comment body:text commentable:references{polymorphic}
  • which generates migration file
class CreateComments < ActiveRecord::Migration
  def change
    create_table :comments do |t|
      t.text :body
  • go to memory first, good for caching
brew install redis
  • start server
redis-server
$ redis-server
78495:C 18 Mar 13:20:12.711 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf

Active admin panel

gem 'activeadmin', github: "activeadmin/activeadmin"
gem "devise"
rails g active_admin:install

Geocoding

gem 'geocoder'
gem 'gmaps4rails'
gem 'underscore-rails'
  • application.js
//= require underscore

Finite State Machine

gem 'aasm'
  • add a aasm state field to the campaign model
g migration add_aasm_state_to_campaigns aasm_state:string:index
  • migration file looks like this: