Giter Site home page Giter Site logo

create_a_blog's Introduction

Request / Response MVC!

  • Fork this repo

  • Clone this repo

  • Create your controllers in app/controllers

    • Make sure they all inherit from ApplicationController
  • Create your routes in config/router.rb

  • Test out all the routes from the assignment using Postman

  • All responses should be in JSON format.

  • Run the server with ruby bin/server.rb

    • Please note: The server will need to be restarted every time you change your code.
  • The server file should be loading all your files in app/controllers and app/models. It has also loaded pry and json for you.

  • You will be using the Postman app for any requests that are not GET requests.

  • All GET requests can be displayed directly in the browser by navigating to the URL requested.

  • In the assignment instructions, if the type of the request is not specified, it can be assumed to be GET.

Defining Routes

  • In config/router.rb you will write your routes using the private methods that are provided.
  • If a route takes an id, you can't create a route for every possible number, so you will use a 'dynamic route'.
  • A 'dynamic route' looks like this :id and the router will look for anything that fits inside of that.
  • If you had a route defined like this get('/tweets/:id, TweetsController, :show) then it would match these urls:
    • /tweets/1
    • /tweets/99999
    • /tweets/foobar
    • /tweets/2/edit <- You probably dont want your show route to match your edit route and thats why..
  • Orders matters with routes in the route file. They are searched from top to bottom and the search stops the first time the router finds a valid route.
  • So your most specific routes need to go first.

Creating a controller

  • All controllers should exist inside of app/controllers/ and their name should follow a pattern. tweets_controller.rb
  • Notice that 'tweets' is plural.
  • The class must also inherit from ApplicationController to work properly with the router.
  • An empty tweets_controller.rb would look something like this:
class TweetsController < ApplicationController
  # your actions go here...
end

create_a_blog's People

Contributors

jah2488 avatar

Watchers

Alex Carmichael 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.