Ruby on Rails

Rails App Structure and Back-end

Hyerang Raina Kim
2 min readJan 10, 2021

MVC

Separation of presentation layer (what the user of the application sees in the browser/mobile device) and the business logic or back-end (invisible layer)

Models are whatever resources that are used in your app.

Views are what the user sees in the browser or in the mobile devices and comprised of HTML, CSS… We’ll use HTML extension (html.erb) for embedded ruby.

Controllers are invisible to user so they technically fall into back-end. How user requests and handle them.

Generate a View

Conventional Expectations

  • Define a route that points to a controller#action
  • Have an appropriately named controller, for example: if dealing with layouts or static pages of the application, a name could be pages_controller
  • Have an appropriately named action, for example: if dealing with a homepage, the action/method could be named home.
  • If done this way, under views, rails will expect a pages folder (named for the pages controller) and a home.html.erb template (named for the home action)

The Back-end: Database and tables in Rails

ORM: Object Related Mapper

  • C: Create
  • R: Read
  • U: Update
  • D: Delete
rails generate scaffold Article title:string description:text

What it created?

  • migration file
  • Articles model
  • Whole bunch of routes
  • Articles controller
  • Whole bunch of views
rails db:migrate

It runs the migration file to create the table.

--

--