Applications are open for the Product College - Apply Now

X

In the previous section, we created the controller and added the route for users.

We are going to create a controller and a route for Memos.

Creating the Memo controller

Since you have some experience creating models, controllers and routes in rails. Can you create the Memo controller and its route?

Hint

Use the rails scaffold_controller generator and don't forget to add your route to the routes.rb file.

Solution for creating the controller:

rails generate scaffold_controller Memo

Solution for creating and adding the Memo route:

Add this to routes.rb

resources :memos

Your routes.rb file will look like this now:

Rails.application.routes.draw do
  resources :users
  resources :memos
end

Your route file should now contain two routes, one for users and another for memos.

Parameter sanitizing for the memo controller

Lets modify the memo_params function to allow parameters for creating a memo.

def memo_params
  params.permit(:title, :text_body, :date)
end

Feedback

If you have feedback on this tutorial or find any mistakes, please open issues on the GitHub Repository or comment below.

Summer academy

An iOS Development Summer Course

Design, code and launch your own app. Locations in San Francisco and Asia

Find your location

Product College

A computer science college

Graduate into a successful career as a founder or software engineer.

Learn more