Giter Site home page Giter Site logo

handson-create_a_rest_api_with_rails's Introduction

Commands

  • rails new <project_name> --api --database=mysql (optional -T for Rspec)
  • rails generate model User username:string password:string
  • rails generate model Fact user:references fact:string likes:integer
  • Go to config/database.yml, update database config
  • rails db:setup
  • rails db:migrate
  • rails g controller api/v1/Users
  • rails g controller api/v1/Facts
  • go to config/routes.rb, update routes into
Rails.application.routes.draw do
  namespace :api do
    namespace :v1 do
      resources :users do
        resources :facts
      end
      resources :facts
    end
  end
end
  • update both UsersController and FactsController
  • Enter console by rails c
$ oliver = User.create( username: 'Oliver', password: 'password' )

$fact_one = Fact.create( fact: 'Wiley Hardeman Post was the first pilot to fly solo around the world.', likes: 1, user_id: 1 )

$ fact_two = Fact.create( fact: 'The Symphony No1 in E flat major, K.16, was written by Wolfgang Amadeus Mozart at the age of 8.โ€™ likes: 2, user_id: 1 )

$ exit

README

This README would normally document whatever steps are necessary to get the application up and running.

Things you may want to cover:

  • Ruby version

  • System dependencies

  • Configuration

  • Database creation

  • Database initialization

  • How to run the test suite

  • Services (job queues, cache servers, search engines, etc.)

  • Deployment instructions

  • ...

Troubleshooting

  • If libssl error is presented, try brew reinstall [email protected] This suggestion also solved the issue with the same error Mac OSX, with Catalina 10.15.3, running mysql 8.0.19, using Rails 5.2 (for what its worth) and already had openssl 1.1.1d installed with Homebrew.

gem uninstall mysql2 brew upgrade openssl gem install mysql2 -- --with-opt-dir="$(brew --prefix openssl)"

handson-create_a_rest_api_with_rails's People

Contributors

shengchuang-wong avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.