Your previous app is great on the client side, but not on the server side. I am going to cover on how to make a rails app. The first thing you need, is rails. Once you have rails installed, go to your command line and write $ rails new 'your app name goes here'
. Then cd
into the new folder you just created. Most rails apps are centered around a database, so let’s start there. In the app you see in the picture, there are 2 models. A model is a class for the data you send in. To make these models, write rails generate model ModelName *properties go here*
. An example of the property syntax looks like this: name:string number:integer boolean:boolean
. So you made the model, but you don’t have any instances of the model. To make one, write $ rails console
. When that loads, write ModelName.create(exampleProperty:"Hi")
. This saves to the database,but doesn’t do anything yet. Your user doesn’t see anything, and there’s no server. To solve the last problem, write $ rails s
. But when you visit localhost:3000, it will throw an error. This is because you need to rake the databse by writing $ rake db:migrate
. As for the first problem, we will cover that in part 2, Controllers and Views.
Leave A Comment