BogoToBogo
  • Home
  • About
  • Big Data
  • Machine Learning
  • AngularJS
  • Python
  • C++
  • go
  • DevOps
  • Kubernetes
  • Algorithms
  • More...
    • Qt 5
    • Linux
    • FFmpeg
    • Matlab
    • Django 1.8
    • Ruby On Rails
    • HTML5 & CSS

Scaffold: A quickest way of building a blog with posts and comments 2020

RubyOnRails_logo




Bookmark and Share





bogotobogo.com site search:





Note

In the subsequent chapters we will create more realistic blog. However, before we do that as a warm up, here we'll create a very simple blog which a user can add posts and comments. So, this chapter will be an express course for making a blog.





Initial steps to take

Rails scaffolding is a quick way to generate some of the major pieces of an application. If we want to create the models, views, and controllers for a new resource in a single operation, scaffolding is the tool for the job.

  1. The first thing we need to do is to create the Rails application:
    $ rails new blog
    
  2. In the blog app directory, use the scaffold generator to create the MVC components needed for posts and comments:
    $ cd blog
    $ rails generate scaffold post title:string body:text
    $ rails generate scaffold comment post_id:integer body:text
    
    Here, we ran a couple of code generators to create The posts as well as the comments.
  3. Create the post and comment database tables:
    $ rake db:migrate
    
    Migrations are Ruby classes that are designed to make it simple to create and modify database tables. Rails uses rake commands to run migrations
  4. $ rake routes
          Prefix Verb   URI Pattern                  Controller#Action
        comments GET    /comments(.:format)          comments#index
                 POST   /comments(.:format)          comments#create
     new_comment GET    /comments/new(.:format)      comments#new
    edit_comment GET    /comments/:id/edit(.:format) comments#edit
         comment GET    /comments/:id(.:format)      comments#show
                 PATCH  /comments/:id(.:format)      comments#update
                 PUT    /comments/:id(.:format)      comments#update
                 DELETE /comments/:id(.:format)      comments#destroy
           posts GET    /posts(.:format)             posts#index
                 POST   /posts(.:format)             posts#create
        new_post GET    /posts/new(.:format)         posts#new
       edit_post GET    /posts/:id/edit(.:format)    posts#edit
            post GET    /posts/:id(.:format)         posts#show
                 PATCH  /posts/:id(.:format)         posts#update
                 PUT    /posts/:id(.:format)         posts#update
                 DELETE /posts/:id(.:format)         posts#destroy
    
    This "rake routes" lists all the URLs currently recognized by our app.
  5. Start the web server:
    $ rails server
    
    and then point our browser to: http://localhost:3000/posts
    blog_post_comment_New_post.png

    If we click 'Create":
    post_1.png


    post_1_edit.png

    We can do comment as well:
    comment.png

    At "Create" button press:
    comment_new.png











Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization

YouTubeMy YouTube channel

Sponsor Open Source development activities and free contents for everyone.

Thank you.

- K Hong






Sponsor Open Source development activities and free contents for everyone.

Thank you.

- K Hong







Ruby on Rails



Ruby On Rails Home

Ruby - Input/Output, Objects, Load

Ruby - Condition (if), Operators (comparison/logical) & case statement

Ruby - loop, while, until, for, each, (..)

Ruby - Functions

Ruby - Exceptions (raise/rescue)

Ruby - Strings (single quote vs double quote, multiline string - EOM, concatenation, substring, include, index, strip, justification, chop, chomp, split)

Ruby - Class and Instance Variables

Ruby - Class and Instance Variables II

Ruby - Modules

Ruby - Iterator : each

Ruby - Symbols (:)

Ruby - Hashes (aka associative arrays, maps, or dictionaries)

Ruby - Arrays

Ruby - Enumerables

Ruby - Filess

Ruby - code blocks and yield

Rails - Embedded Ruby (ERb) and Rails html

Rails - Partial template

Rails - HTML Helpers (link_to, imag_tag, and form_for)

Layouts and Rendering I - yield, content_for, content_for?

Layouts and Rendering II - asset tag helpers, stylesheet_link_tag, javascript_include_tag

Rails Project

Rails - Hello World

Rails - MVC and ActionController

Rails - Parameters (hash, array, JSON, routing, and strong parameter)

Filters and controller actions - before_action, skip_before_action

The simplest app - Rails default page on a Shared Host

Redmine Install on a Shared Host

Git and BitBucket

Deploying Rails 4 to Heroku

Scaffold: A quickest way of building a blog with posts and comments

Databases and migration

Active Record

Microblog 1

Microblog 2

Microblog 3 (Users resource)

Microblog 4 (Microposts resource I)

Microblog 5 (Microposts resource II)

Simple_app I - rails html pages

Simple_app II - TDD (Home/Help page)

Simple_app III - TDD (About page)

Simple_app IV - TDD (Dynamic Pages)

Simple_app V - TDD (Dynamic Pages - Embedded Ruby)

Simple_app VI - TDD (Dynamic Pages - Embedded Ruby, Layouts)

App : Facebook and Twitter Authentication using Omniauth oauth2

Authentication and sending confirmation email using Devise

Adding custom fields to Devise User model and Customization

Devise Customization 2. views/users

Rails Heroku Deploy - Authentication and sending confirmation email using Devise

Deploying a Rails 4 app on CentOS 7 production server with Apache and Passenger I

Deploying a Rails 4 app on CentOS 7 production server with Apache and Passenger II

OOPS! Deploying a Rails 4 app on CentOS 7 production server with Apache and Passenger (Trouble shooting)











Contact

BogoToBogo
contactus@bogotobogo.com

Follow Bogotobogo

About Us

contactus@bogotobogo.com

YouTubeMy YouTube channel
Pacific Ave, San Francisco, CA 94115

Pacific Ave, San Francisco, CA 94115

Copyright © 2024, bogotobogo
Design: Web Master