Rails g resource: A Flatiron School Post
Mod 2 of Flatiron School and we’re tasked using the Model-Views-Controller model to create apps. I’ve created a few of my own apps and asked around about what my friends wanted to create. I find that making my own apps from scratch really helps me practice what I learned in class and apply it to the real world. It feels really empowering to be able to start to see how my apps can be applied in a real life situation.
The Rock has had this moment called the Seven Bucks moment and he named his production company after it. So with seven dollars and minimal resources, what can we create? An app. That’s what. So let’s get this thing rollinggg!

Let’s start by making a new rails project in the terminal by typing in… you guessed it! rails new project
. This just creates a new project and initializes a bunch of folders that we can work with.

Now we have to “change directories” into the project folder. The way to do this in the terminal is cd project
. A directory is the same thing as a folder. We interact with them all the time as we make new folders and files to keep everything organized.

Now let’s open up the project in Atom. Atom is a text editor, and we can open up the whole folder/directory using atom .
.

We can generate a new resource using rails g resource <insert_model_name_here> <attribute_name>:<attribute_type>
. If this seems a bit overwhelming, just refer to the example on the side.

That’ll create all these folders for you, and if you’ve correctly created your model, you’ll see this output in your terminal.

If you open up atom, you’ll see all these folders that have been created. In my case, the main folders to focus on are app/controllers/users_controller.rb
, app/models/user.rb
and db/migrate
. It’ll create a controller for you to write your actions in and a user model for you as well. The db/migrate
folder contains a migration as well, which will set up your table for you. You just have to seed your data in db/seeds.rb
. In config/routes.rb
, your routes have also been set up as well.

Run rails db:migrate
to migrate your table.

Now fire up rails s
and that’ll start your server.

To make sure everything is up and running, go to localhost:3000
and you should see this page.
Make sure your code doesn’t smell or else The Rock will know.