Skip to content

Instantly share code, notes, and snippets.

@jennli
Last active July 20, 2020 01:27
Show Gist options
  • Save jennli/33b04b7ad966b301cc73b0b96651618a to your computer and use it in GitHub Desktop.
Save jennli/33b04b7ad966b301cc73b0b96651618a to your computer and use it in GitHub Desktop.
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

create database

rails db:create

create controller

scaffold:

rails g scaffold product name:string category:text dimensions:string rank:string asin:string
rails g controller products index show create
rails g model product name category dimensions

migrate

rails db:migrate

seed

go to db/seed.rb

10.times do |number|
 Product.create(name: "product #{number}", dimensions: "#{number}", category: "#{number}", rank: "#{number}", asin: "asin-#{number}" )
end

update routes if not scaffold

root "products#index"
resources :products, only: [:index, :show, :create]

include react to view erb file

<%= javascript_pack_tag 'hello_react' %>

add bootstrap

yarn add bootstrap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment