Set up Rails Controller

Tanuka Das
2 min readDec 23, 2019

--

The controller does the heavy lifting when the interaction happens between the model, server and user. It handles all the complex logic, communication, saving things to the database, rendering partials, giving feedback to the user, etc.

Step 1: Generate the controller

That creates tones of files, one of the most important being, app/controllers/hats_controller.rb, the hat's controller. It has a class called HatsController and it inherits from the application controller. All the actions, methods for this controller will go between the class declaration and the end, at the bottom.

Step 2: Define the routes

Add this in the config/routes.rb file. This defined resources, hats, create a whole bunch of possible addresses we can use inside of our browser; if you run rails routes on the console, it will display all of those possible addresses that can be used to build the application.

Step 3: Open the server

This will lead to the rails http://localhost:3000/ browser, which is rails welcome page and if you go to the http://localhost:3000/hats it will show you a missing template error hats/index.

Congratulations! Now you can perform the full CRUD actions with your hats controller.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Tanuka Das
Tanuka Das

Written by Tanuka Das

Software Developer, technical writer, bookworm, constant learner.

No responses yet

Write a response